API Paradigms
Application Programming Interface
Representational State Transfer
- Resources based
- Which use only nouns rather than verb
- Can apply CRUD operations on them
- Match them to http verbs
- REpresentation State Transfer
- built on top of http
- has to be stateless, not state on the server
- pagination, information and states should be stored in requests
- to avoid issues in multi server systems
- Communicate usually in json formate
- Non-CRUD action such as Archive need to included the information in the body
- Or something like search, which need to use additional query parameters
Advantages
- Utilised HTTP feature, can integrate into browser easily
- Standard methods names, arguments and status codes
- Easy to maintain
Disadvantages
- Big and unnecessary payloads
- Multiple HTTP roundtrips to get different resource, can not combine them
Remote procedure call (RPC)
- Enables one machine to invoke some code on another machine as if it is a local function call from user's perspective
Advantages
- Easy to understand
- Lightweight payload
- Payload only associate with the action itself
- High performance
- Since they are only action oriented
Disadvantages
- Discovery is difficult
- Limited standardisation
- Leads to function explosion
- Number of endpoint exploded as feature grows
GraphQL
- only use http post request
- for REST, over-fetching and request obsolete information may happen
- client on get the data field that they need
- single endpoint
- query
- mutation
- have schema, less flexible