Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Stargate: an interstellar journey to RESTful APIs

34 vues

Publié le

by Juan Escalada

This talk will present [Stargate](htts://github.com/ba-st/Stargate), a library supporting the creation of HTTP based RESTful APIs.
The library is built on top of Teapot and Zinc, providing a conceptual framework to simplify the creation of RESTful APIs including HATEOAS, content negotiation, API versioning, ETags and pagination.
We will revisit the library affordances and a real world experience report using it.

Publié dans : Logiciels
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Stargate: an interstellar journey to RESTful APIs

  1. 1. Stargate An interstellar journey to restful APIs Sponsored by
  2. 2. Hello! I AM JUAN ESCALADA Software Developer @ Mercap Software 2
  3. 3. Agenda ⋆ Intro ⋆ Features ⋆ Architecture ⋆ Live Demo ⋆ Conclusion ⋆ Future Work 3
  4. 4. Intro What’s Stargate? It is an MIT-licensed library supporting the creation of HTTP based RESTful APIs… ba-st/Stargate
  5. 5. What’s Stargate? … built on top of Zinc HTTP components and Teapot ⋆ Zinc is used as HTTP Server ⋆ Teapot is used for routing 5
  6. 6. rest 6 L3 HATEOAS L2 Multiple URIs Multiple Verbs L0 One URI One Verb Richardson Maturity Model L1 Multiple URIs One Verb Principles ⋆ Client-Server ⋆ Stateless ⋆ Cacheable ⋆ Uniform interface ⋆ Layered system
  7. 7. Example: Pet store 7 Supported media types ⋆ application/vnd.stargate.pet+json;version=1.0.0 ⋆ application/vnd.stargate.pet+json;version=1.1.0 ⋆ application/vnd.stargate.pet+json;version=2.0.0 ⋆ application/vnd.stargate.pet.summary+json;version=1.0.0 Available endpoints ⋆ /pets ⋆ GET ⋆ POST ⋆ OPTIONS ⋆ /orders ⋆ POST ⋆ OPTIONS
  8. 8. Features 8
  9. 9. Features Content Negotiation HATEOAS Hypertext as the Engine of Application State Caching control 9 Pagination CORS Cross Origin Resource Sharing Error Handling Health check Metrics
  10. 10. Content negotiation Supported media types ⋆ application/vnd.stargate.pet+json;version=1.0.0 ⋆ application/vnd.stargate.pet+json;version=1.1.0 ⋆ application/vnd.stargate.pet+json;version=2.0.0 ⋆ application/vnd.stargate.pet.summary+json;version=1.0.0 10 Accept: Content Type: application/vnd.stargate.pet+json;version=1.0.0 application/vnd.stargate.pet+json;version=1.0.0 */* application/vnd.stargate.pet+json;version=2.0.0 application/vnd.stargate.pet.summary+json application/vnd.stargate.pet.summary+json;version=1.0.0 application/xml 406/Not Acceptable
  11. 11. 11 Content negotiation Supported media types ⋆ application/vnd.stargate.pet+json;version=1.0.0 ⋆ application/vnd.stargate.pet+json;version=1.1.0 ⋆ application/vnd.stargate.pet+json;version=2.0.0 ⋆ application/vnd.stargate.pet.summary+json;version=1.0.0 Accept: Content Type: application/vnd.stargate.pet+json;version=1 application/vnd.stargate.pet+json;version=1.1.0 application/vnd.stargate.pet+json;version=1.0 application/vnd.stargate.pet+json;version=1.0.0 application/json;version=2 application/vnd.stargate.pet+json;version=2.0.0 application/vnd.stargate.pet+json;version=2 application/vnd.stargate.pet+json;version=2.0.0
  12. 12. HATEOAS { "pet": "1", "date": "2018-10-24T18:05:46.418Z", "status": "registered", "links": { "complete": "https://petstore.example.com/orders/1/complete", "self": "https://petstore.example.com/orders/1", "cancel": "https://petstore.example.com/orders/1/cancel" } } 12 Hypermedia as the Engine of Application State
  13. 13. Caching Control ⋆ ETags are generated on 200/OK 201/Created responses ⋆ When If-None-Match header is present in a GET a 304/Not Modified response is created ⋆ Updates/deletes automatically raise a 428/Precondition required error when If-Match header is missing ⋆ When If-Match header is present a 412/Precondition Failed error is raised if the ETag doesn’t match 13
  14. 14. Error Handling “Stargate, we have a problem” Stargate will handle common error situations and produce the corresponding responses: ⋆ 400/Bad Request on invalid or missing query parameters or decoding errors ⋆ 404/Not Found when the resource lookup fails ⋆ 409/Conflict when the resource to update/create conflicts with another one ⋆ 415/Unsupported media type when the Content Type cannot be handled 14
  15. 15. Metrics ⋆ Endpoint: /metrics ⋆ Allowed HTTP methods: GET ⋆ Supported media types: ⋆ text/plain: In prometheus client data exposition format ⋆ text/vnd.stargate.prometheus.client-data-exposition;version=0.0.4 ⋆ application/vnd.stargate.operational-metrics+json ⋆ Authentication: Required ⋆ Authorization: Requires read:metrics ⋆ Expected Responses: 200 OK 15
  16. 16. Health Check ⋆ Endpoint: /health-check ⋆ Allowed HTTP methods: POST ⋆ Supported media types: ⋆ application/vnd.stargate.health-check.details+json ⋆ application/vnd.stargate.health-check.summary+json ⋆ Authentication: Required ⋆ Expected Responses: ⋆ 200 OK if the overall health condition is not critical ⋆ 503 Service Unavailable if the overall health condition is critical 16
  17. 17. Architecture 17
  18. 18. 18 Zinc Server Teapot Server /pets /pets/{id} /orders /orders/{id}/comments /currencies ResourceRESTfulController PetsRESTfulController OrdersRESTfulController CurrenciesRESTfulController requestHandler ordersRequestHandler commentsRequestHandler requestHandlerHTTP Requests HTTPBasedRESTfulAPI
  19. 19. Live Demo 19
  20. 20. Conclusions Stargate is a good option if: ⋆ You want to implement an hypermedia driven API ⋆ You need advanced content negotiation ⋆ Or just need a way to structure your complex HTTP REST API 20
  21. 21. Future Work ⋆ Improve cache control support: cache-control directives, Last-Modified and Expires ⋆ Operational plugins ⋆ Configuration ⋆ Application Info ⋆ Application control ⋆ Loggers 21
  22. 22. 22 Thanks! ANY QUESTIONS? j.escalada@mercapsoftware.com ba-st/Stargate Sponsored by
  23. 23. Credits Special thanks to Mercap Software, the “Financial IT Experts”, for sponsoring my trip and this presentation. 23

×