Skip to content

Instantly share code, notes, and snippets.

@danilobatistaqueiroz
Last active September 27, 2018 13:34
Show Gist options
  • Select an option

  • Save danilobatistaqueiroz/7c7117f5d6bb39a35aa72737b1918f6c to your computer and use it in GitHub Desktop.

Select an option

Save danilobatistaqueiroz/7c7117f5d6bb39a35aa72737b1918f6c to your computer and use it in GitHub Desktop.
Rest API essentials

With the rise of mobile development and JavaScript frameworks, using a RESTful API is the best option to build a single interface between your data and your client.

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. Some endpoints are pretty straightforward and, as a result, your API will be much more easier to use and maintain

There are many ways to implement API Authentication in Laravel (one of them being Passport, a great way to implement OAuth2)

Some of the common HTTP result codes that are often used inside REST APIs are as follows:

200 - “OK”.
201 - “Created” (Used with POST).
400 - “Bad Request” (Perhaps missing required parameters).
401 - “Unauthorized” (Missing authentication parameters).
403 - “Forbidden” (You were authenticated but lacking required privileges).
404 - “Not Found”.

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.

There are many advantages using Restful API:

  • simplicity: the http protocol is almost universal and all languages comes with support for it.
  • standard: when using json you are using javascript, in the web, javascript is a standard.
  • lightweight: only using http and json is very straightforward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment