Skip to content
Advertisement

Basic question about REST APIs enpoint creation and access and how to create an app script

I’ve been recently learning about REST APIs (concretely using MySQL and PHP) so it’s hard for me to understand basic concepts since most of the sites I check have more advanced solutions.

My doubt is the following: I know that an endpoint is the place where we get the data, but I’m not sure about the URI format, sometimes I’ve seen it as a php file path and other times it doesn’t have an extension, but I don’t know which one is correct, or if both are.

  1. In case the URI format has no file extension (like performing a GET in the endpoint /api/update), do I forcefully have to have a “controller” file to which all the URIs are redirected and treated depending on the case, or is there a better way to handle them?

  2. I’ve also been asked to make a script to run a backend app and a frontend and backend app, as in a script that will execute everything when launched (calling other scripts if necessary and so on) but I don’t know what they mean exactly by that or how to do it. I thought that having a index.php (for example) in which you can have a couple of buttons that would trigger the requests was already it but it’s not, so what is it exactly?

Sorry for the basic questions but I’ve looked many solutions in here and other websites and I still can’t grasp the concept.

Thanks in advance.

Advertisement

Answer

  1. The answer to this question is yes. Common practice is to have a PHP application use the front controller pattern, where a single publicly available script (usually index.php) is solely responsible for delegating all incoming requests to the appropriate part of your application (your actual “controllers”), often relying on server configuration to do the actual “redirecting” (rewriting, allowing for omitted file extensions and “pretty url’s”). This design approach is common because most popular frameworks support it out of the box, from the Laravel and Symfony big boys, to microframeworks like Slim, Silex and Lumen. Perhaps giving these frameworks a try will help you understand how this works and how they do it.

  2. Not sure if I understand your question correctly, but it sounds like you are being asked to provide/implement a deployment script; a script that runs a set of commands in order to easily install, bootstrap and start the entire application. Think of commands like composer install, commands that initialize/seed the database, or commands that build your frontend assets. The actual commands are specific to the application, but the goal is to easily provide a fresh installation and deployment of your application by executing a single script. These scrips are usually sh scripts executed from the command line.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement