Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RESTful APIS - Let your apps talk to each other

Lucas Mendes
December 15, 2016

RESTful APIS - Let your apps talk to each other

Do you know the right way and correct techniques to develop a good scalable RESTful API? This talk covers the misconceptions and the pragmatism around this architectural style, highlighting some important concepts to make your API achieve two important points: adoption and scalability.

Lucas Mendes

December 15, 2016
Tweet

More Decks by Lucas Mendes

Other Decks in Technology

Transcript

  1. RESTFUL APIS LET YOUR APPS TALK TO EACH OTHER Lucas

    Mendes (@devsdmf) Lead Backend Engineer, ISET www.iset.com.br
  2. ABOUT ME code writer, software architect, open source lover, musician

    and writer in free hours. MIM ACHER [email protected] www.devsdmf.io github.com/devsdmf about.me/devsdmf twitter.com/devsdmf
  3. COMPUTER NETWORK A computer network or data network is a

    telecommunications network which allows nodes to share resources. [...] The best-known computer network is the Internet.
  4. THE OSI MODEL The Open Systems Interconnection model (OSI model)

    is a conceptual model that characterizes and standardizes the communication functions of a telecommunication or computing system without regard to their underlying internal structure and technology.
  5. TCP/IP The Internet protocol suite is the conceptual model and

    set of communications protocols used on the Internet and similar computer networks.
  6. THE HTTP PROTOCOL The Hypertext Transfer Protocol (HTTP) is an

    application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. The HTTP is designed to enable communications between clients and servers and works as a request-response protocol between a client and server.
  7. HTTP STATUS CODES 1xx: Information 2xx: Successful 3xx: Redirection 4xx:

    Client Error 5xx: Server Error 100 Continue 200 OK 301 Moved Permanently 400 Bad Request 500 Internal Server Error 101 Switching Protocols 201 Created 302 Found 401 Unauthorized 502 Bad Gateway
  8. HTTP STATUS CODES 1xx: Information 2xx: Successful 3xx: Redirection 4xx:

    Client Error 5xx: Server Error 103 Checkpoint 204 No Content 304 Not Modified 403 Forbidden 503 Service Unavailable 205 Reset Content 404 Not Found 504 Gateway Timeout
  9. WHAT IS REST? Representational state transfer (REST) or RESTful web

    services are one way of providing interoperability between computer systems on the Internet.
  10. JSON DOCUMENT { "title": "RESTful APIs", "subtitle": "Let your apps

    talk to each other", "presenter": { "name": "Lucas Mendes", "email": "[email protected]" }, "tags": ["rest","api"] }
  11. GETTING A RESOURCE GET /CUSTOMERS/123 { "name": "Lucas Mendes", "email":

    "[email protected]", "orders": [ { "href": "https://api.payment.com/orders/456" } ], "accountStatus": "active" }
  12. CAMELCASE 'JS' IN 'JSON' = JAVASCRIPT WRONG: RIGHT: { "user_name":

    "Lucas Mendes" } { "userName": "Lucas Mendes" }
  13. RESPONSE BODY GET OBVIOUS WHAT ABOUT POST? RETURN THE REPRESENTATION

    IN THE RESPONSE WHEN FEASIBLE ADD OVERRIDE (?_BODY=FALSE) FOR CONTROL
  14. INSTANCE WITH HREF GET /CUSTOMERS/123 { "name": "Lucas Mendes", "email":

    "[email protected]", "orders": [ { "href": "https://api.payment.com/orders/456" } ], "accountStatus": "active" }
  15. ERROR RESPONSE POST /CUSTOMERS 400 BAD REQUEST { "status": 400,

    "code": "12345", "property": "email", "message": "The specified email address is already taken", "moreInfo": "https://www.payments.com/docs/api/errors/12345" }
  16. CACHING RESOURCES Use HTTP cache Use cache servers for increase

    the performance Return a 304 Not Modified when the resource is cached
  17. SECURITY GUIDELINES Avoid sessions when possible: Authenticate every request if

    necessary Stateless Authorize based on resource content, NOT URL! Use Existing Protocol: OAuth 1.0a, OAuth 2.0, Basic over SSL only Custom Authentication Scheme: Only if you provide client code / SDK Only if you really, really know what are you doing Use API Keys instead of Username/Passwords
  18. 401 VS 403 401 "Unauthorized" really means Unauthenticated "You need

    valid credentials for me to response to this request" 403 "Forbidden" really means Unauthorized "I understood your credentials, but so sorry, you're not allowed!"
  19. SDK

  20. STATE OF THE ART “State of the art (sometimes cutting

    edge) refers to the highest level of general development, as of a device, technique, or scientific field achieved at a particular time. It also refers to such a level of development reached at any particular time as a result of the common methodologies employed at the time.”