r/PHPhelp • u/AngelSlash • Dec 11 '24
Solved Creating a REST API
Hello everyone
As the title says I'm trying to create a REST API. For context, I'm currently creating a website (a cooking website) to learn how to use PHP. The website will allow users to login / sign in, to create and read recipes. After creating the front (HTML, CSS) and the back (SQL queries) I'm now diving in the process of creating my API to allow users to access my website from mobile and PC. (For context I'm working on WAMP).
The thing is I'm having a really hard time understanding how to create an API. I understand it's basically just SQL queries you encode / decode in JSON (correct me if I'm wrong) but I don't understand how to set it up. From what I've gathered you're supposed to create your index.php and your endpoints before creating the HTML ? How do you "link" the various PHP pages (for exemple I've got a UserPage.php) with the endpoints ?
Sorry if my question is a bit confusing, the whole architecture of an API IS still confusing to me even after doing a lot of research about it. Thanks to anyone who could give me an explaination.
View all comments
Show parent comment
0
u/equilni Dec 12 '24 edited Dec 12 '24
EDIT - I don't understand the downvotes. I am agreeing, but asking for more clarification on the reasons...
I agree with using a tool to help with lower level tasks like for SQL, using a Query Builder (preferred - like Doctrine DBAL, or Laravel) or ORM.
That said, I don't understand your reasoning for doing so.
This will be true in plain SQL vs QB vs ORM.
Repeat each for each of your model/entity:
Send the above example to a service or controller, the underlying storage mechanism is abstracted away, so it doesn't matter SQL, QB or ORM..
You didn't explain how or show an example.