1. Why should I care
about REST?
Taking advantage of REST today!
Raúl Sánchez
Víctor Martínez
Antonio Hernández
Miguel Sánchez
Adrián Muro
Julio Tinajero
6. HTTP
Headers
• Request Headers
Accept: Tells the server what type of content we want
Authorization: Sends our credentials to the server
• Response Headers
Content-Type: Tells us about the content of a response
Content-Length: Tells us about the content of a response
8. HTTP
Status Codes
Sample HTTP 404 error page at github.com
• 1xx: Informational
• 2xx: Success
• 3xx: Redirection
• 4xx: Client Error
• 5xx: Server Error
See https://devhints.io/http-status
9. REST
REpresentational State Transfer
• An architectural style
• Uses a subset of HTTP
• Modeling is resource based
• Typically uses JSON for resource representation
11. Who uses REST?
TLDR; A lot of people
• GitHub: https://docs.github.com/en/rest
• GitLab: https://docs.gitlab.com/ee/api/
• Kubernetes: https://kubernetes.io/docs/concepts/overview/kubernetes-api/
• Twitter: https://developer.twitter.com/en/docs/twitter-api
• Spotify: https://developer.spotify.com/documentation/web-api/
• Google Spreadsheets: https://developers.google.com/sheets/api
Find lots of public APIs in https://github.com/public-apis/public-apis
12. How to use REST
cURL
• Lives in the command line
• Is virtually available anywhere
• Important options
-L Follow redirects
-k Allow insecure SSL certs
-X Set the HTTP Method
-H Set a header
-u BASIC Authentication
-v Debugging output
-s No progress output
13. How to use REST
cURL + jq
• Install jq
brew install jq
• Use jq
curl -s http://... | jq
14. How to use REST
Google Chrome + JavaScript
• Use the DevTools
await fetch(
'<URI>',
<OPTIONS>
)
.then(
response => response.json()
);
See the fetch documentation at
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
15. How to use REST
Postman
• Allows to define request collections
• Saves history
• Allows to generate code to test APIs
• Has a CLI app to run tests
Download Postman from
https://www.postman.com/
16. How to use REST
Swagger/OpenAPI
• Allows to define a REST api as JSON
or YAML
• Can generate a UI to test your API
• Can generate code to test your API
• Can be imported into postman
Use Swagger Editor at
https://editor.swagger.io/