Remember that the URLs should not contain verbs and that resources are not necessarily rows in a table. However, there will be cases where it will be hard to map to a Create/Retrieve/Update/Delete schema. I’ve built terrible APIs like that in the past and I still hate myself for it. Some endpoints are pretty straightforward and, as a result, your API will be much more easier to use and maintain as opposed to having endpoints such as GET /get_article?id_article=12 and POST /delete_article?number=40. The greatest advantage of using a set of conventions such as REST is that your API will be much easier to consume and develop around. In the end, you get to decide how to architect resources and models in a way that is fitting to your application. You can have resources represented in more than one data model (or not represented at all in the database) and models completely off limits for the user. In this laravel api tutorial, the resources will have a 1:1 representation on our data models, but that is not a requirement. Resources will be the targets of the actions, in our case Articles and Users, and they have their own endpoints: Another requirement for the PUT verb is idempotence, which in this case basically means you can send that request 1, 2 or 1000 times and the result will be the same: one updated resource in the database. In this article we’ll be using PUT for the update action, as according to the HTTP RFC, PUT means to create/update a resource at a specific location. RESTful APIs are a matter of much debate and there are plenty of opinions out there on whether is best to update with POST, PATCH, or PUT, or if the create action is best left to the PUT verb.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |