简体   繁体   中英

PHP file on the server vs REST interface with abstract methods

I can create a PHP file on my sever that will handle GET POST PUT DELETE requests, and I can can return the correct data for each case to the requestor from the same file.

example:

user.php (if someone sends a REQUEST to user/ or user/1 they will get back a seemingly RESTful response of all users or the one they requested).

I am having a tough time understanding why I need to build a REST interface instead of just writing the correlating PHP files for each endpoint I want to expose?

So after building my REST server using 3 different methods, I now fully understand the need to abstract out the interface. It is far simpler to maintain one point of entry then 10 or 20 different PHP files.

don't get me wrong, at first, when implementing the abstract interface, you will write a lot more code, but it quickly saves you hours of time in the long run. It also allows you to stay flexible and interchangeable.

my summary:

if you just need quick and dirty go php file!!

But, if you plan on building something secure and scalable, bite the bullet and build the interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM