Build a Simple REST API in PHP

Daktau

I have just signed up for a okta account and found this article which I am following but have quickly found myself not knowing stuff I feel I should know.

What devEnv do I need for this for my laptop?

Where is the command “composer install” being typed? In okta or on the machine with the code?

many thanks!

Matt Raible

This should be typed on your local machine, in a terminal window.

Daktau

Thanks for this. Having given it more time I’ve now worked out I need a local php dev env which then requires the composer application. Now it makes more sense, I was naively expecting to be given this info what with the title of the document being “Build a Simple REST API in PHP”.

Martijn Deleij

Why do you need tokens / authorization if this is machine to machine? Wouldnt the endpoint be easily programmed to just serve requests from the application id?

rotesfahrrad

This seems to be a good point at first sight. I don’t know if I understand you correctly, but if you use the API merely for your own use or for an app that makes the requests invisibly in the background, then maybe that can work.

But if, for example, you are using the API to give a customer certain insights into their customer account via the browser, then the API should be secured against the customer being able to overstep their rights (with details visible in the query, e.g. via the browser console or similar).

Zipora Ressl

can anyone help me?

When I type this:
composer require okta/jwt-verifier spomky-labs/jose guzzlehttp/psr7

I get a message: Installation failed, reverting ./composer.json to its original content.

Does anyone know what I did wrong?

Alonzo

Wow really great article - it help me a lot in building my API in php. I have started from tutorial in this article https://dev-bay.com/php-how… and I extended that example with data base connection as you did in tutorial here, what have me really impressive results.

One question - will your solution work fully properly with php 7.0?

Krasimir Hristozov

Yes, it should work fine with PHP 7.0+

diggs

Krasimir, this was an absolute kick-ass overview of building an API. I especially appreciate how lightweight it is, skipping the Person class, and limiting external library requirements, while still being well-organized.

Really nicely written.

Dilas

Hi, this is a well documented article, but i have a little problem, after i have set all the okta credentials but i am still getting Obtaining “token…failed, exiting” maybe i am doing something wrong, kindly help out.

Spiderangelo .com

You call this simple!!! I hate all platform managers, idotic dependencies, and in between jumping to commandline. There is NOT even a single useful tutorial about APIs. For doing something in php why should one go commandline jigmaroles???

Kishiro80

seems like you dont know what is rest API.

Its better if you just stick with whatever you think as “simple”

gyan mishra

actually the settings given here is failing at line number 45 where the response is generated. var_dump($response) and see if you are getting “invalid scope” error

Nasibullo Mukhamedov

it seems for php experts, otherwise there is no explanation about file structure