RESTful API (with RoR)
RESTful API (with RoR)
1. What is API?
2. Why API is needed?
3. How to Build RESTful API?
4. OAuth2 Protocol
5. API Performance Enhancement
6. API Documentation
7. Some HTTP Status Code
What is API?
● Authentication vs Authorization
● Old-School Authentication
○ Embed username and password in the every requested endpoints
■ (e.g. /operators?username=xxx&password=xxx)
○ URLs can be copied and shared to others
○ URLs most likely be logged in the server log
● OAuth2 ⇒ a popular protocol for building a secured API
○ Use access token to authorize the application
○ Embed access token in the header
○ Most servers will not write header logs
○ Can set expired time of the access token
○ RoR gem ⇒ doorkeeper
OAuth2 Flow
POST /oauth/token
GET /operators
OAuth2 Flow (Cont’)
POST /oauth/token
● https://searchmicroservices.techtarget.com/definition/RESTful-API
● https://www.mulesoft.com/resources/api/what-is-rest-api-design
● https://blog.readme.io/the-history-of-rest-apis/
● https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
Questions & Answers