REST API

What is RESTful API?

Roy Fielding - The author

REST was defined in 2000 by Roy Fielding and is considerably simpler. It’s not a standard but a set of recommendations and constraints for RESTful web services (or architectural style).

REpresentational State Transfer

  • Client-Server - SystemA makes an HTTP request to a URL hosted by SystemB, which returns a response. It’s identical to how a browser works.
  • Stateless - REST is stateless: the client request should contain all the information necessary to respond to a request. In other words, it should be possible to make two or more HTTP requests in any order and the same responses will be received.
  • Cacheable - A response should be defined as cacheable or not.
  • Layered - The requesting client don't need to know whether it’s communicating with the actual server, a proxy, or something else.

RESTful API Style

It is not a RESTfull, but RESTful, that means "REST-like"

Request anatomy

Request consists from: 

  • endoint
  • method
  • headers
  • data

Endpoint

https://domain.com/user/1/articles?page=3&published=true

domain (+ port)

query string

path

Method (CRUD-operations)

  • GET - read
  • POST - create
  • PUT / PATCH - update
  • DELETE - delete

Headers

  • Access-Control-Allow-Credentials: true
  • Access-Control-Allow-Methods: PUT, DELETE
  • Access-Control-Allow-Origin: http://example.org
  • Cache-Control: private, no-cache, must-revalidate
  • Connection: Keep-Alive
  • Content-Type: application/json
  • Set-Cookie: test=1; domain=example.com; path=/; expires=Tue, 01-Oct-2013 19:16:48 GMT

 

Data (JSON)

{
  "name": "John Doe",
  "age": 33,
  "articlesNumber": 120,
  "active": true,
  "city": null
}

Create RESTful API with JSON-server

live-coding

Homework

Materials

Thank you
&
QA

Made with Slides.com