REST, RESTful API

download REST, RESTful API

of 69

  • date post

    27-Aug-2014
  • Category

    Software

  • view

    266
  • download

    0

Embed Size (px)

description

 

Transcript of REST, RESTful API

  • REST, RESTful API
  • API
  • Developers as Customers
  • Make APIs Easy to Learn
  • Design APIs Well
  • Bad designed APIs ...
  • /getUser /getAllUsers /findUser /findUserAccounts /deleteUser /changeUserPass ...
  • API Consumers
  • API Designers
  • Simplicity
  • REST is your friend
  • Base URLs per each resource
  • Collection /users
  • Entity /users/hossein /users/13246
  • HTTP Verbs
  • POST GET PUT DELETE PATCH ...
  • C.R.U.D. Operations
  • C. POST
  • R. GET
  • U. PUT
  • D. DELETE
  • PUT is also used for creating
  • PATH for partial updates
  • Verb Resource POST GET PUT DELETE /users New User List Users ? Delete Everybody /users/hossein ? Show Hossein :) Update / Create Hossein Delete Hossein :(
  • Resources as Nouns
  • Plural Nouns
  • Stop using Verbs
  • Verb Resource POST GET PUT DELETE /users New User List Users ? Delete Everybody /users/hossein ? Show Hossein :) Update / Create Hossein Delete Hossein :(
  • Associations
  • Chaining resources together
  • Chaining resources together /users/hossein/accounts
  • Nesting too much
  • Complexitymay arise
  • Keep Base URL Simple
  • ? Query String
  • ? Query String /users?state=pending
  • Params in Headers
  • Pagination
  • Offset / Limit
  • Page number
  • Start / Count
  • HATEOAS
  • Hypermedia As The Engine Of Application State
  • GET /account/12345 HTTP/1.1 HTTP/1.1 200 OK 12345100.00
  • GET /account/12345 HTTP/1.1 HTTP/1.1 200 OK 12345-30.00
  • Versioning
  • Date /2014-04-05/...
  • Decimal Point /v1.0/...
  • In Query String ?v=1
  • Integer :) /v1/ /v2/
  • Leftmost in the URI
  • Header
  • Be Explicit
  • Limiting Entity Fields
  • Limiting Entity Fields /users:(id,first-name)
  • Limiting Entity Fields /users?fields=id,first-name
  • Formats (JSON, XML)
  • Header Content-Type: application/json
  • Extension /users.json
  • Query String /users?type=json
  • Error Handling
  • HTTP Status Codes
  • Error Messages
  • Linking to comprehensive explanation
  • Domain
  • Domain api.example.com
  • Domain dev.example.com
  • Domain example.com/api/