You are on page 1of 10

REST

For Beginners

REST

Is the Industry adopted method for building APIs

Its based around the HTTP methods of

GET

POST

PUT

DELETE

With the use of HTTP methods, we also use the HTTP status
codes

REST and CRUD

POST = Create

GET = Read

PUT = Update

DELETE = Delete

Use of POST

If youre sending information to the server, you


should use the HTTP POST method, whether this is
for posting a blog article, or logging in.

Post usually goes to a generic endpoint

Use of GET

When youre requesting information from the server,


whether if be publicly accessible or not, you should
use the GET Method

GET usually is performed on a specific resource.

GET on an endpoint would usually return a list of


resources.

Use of PUT

PUT is used in two instances, the first being if you


want to update a resource, the second being if you
want to create a resource and specifically name it.

PUT is always used on a resource

Use of DELETE

DELETE is used when you wish to delete content


from your database (however this may be a softdelete).

DELETE is used on a resource

HTTP status codes

200 - Everything is ok

400 - Bad Request


You havent sent the correct fields in a POST

401 - Unauthorised
Authentication has failed

402 - Payment Required


Not usually used, but if youre behind a pay-gate and you haven't paid, this is the expected status

403 - Forbidden
Authentication has succeeded but access levels prevent the user from accessing this content

404 - Not Found


This content doesn't exist

HTTP status codes

408 - Request Timeout


An upstream service has taken too long to respond

410 - Gone
There used to be content here, its been deleted

429 - Too Many Requests


This is appropriate for when a user has made multiple requests to the same service in a
period of time

450 - Blocked by Windows Parental Controls (Microsoft only)


Sorry, but windows parental controls have blocked this

500 - Internal Server Error


Something has gone seriously wrong

Finally

201 - Created
This is the HTTP header we should use when creating new records
however a number of frameworks including AngularJS works on the basis
of IF NOT 200, THEN ITS AN ERROR

418 - Im a Teapot
Some how an April Fools joke made it into the official HTTP status codes.

420 - Enhance Your Calm


Same as 429, Too Many Requests

You might also like