DEV Community

Sakshi
Sakshi

Posted on • Edited on

Design a RESTful API

This blog is all about introduction to RESTful API design, it gives idea about What, Why and How of the same.

HTTP is expressive, ubiquitious and powerful.
API design is complex, a game of trade offs.

STEPS OF DESIGNING API

  • Decide what functionalities to expose,
  • Then how to expose,
  • What to expose and,
  • Adjust and improve according to use cases
  • Rethink and improve

Consider a coffee cup, you can't hold a cup filled with hot coffee. There we need a handle, this helps you to hold the cup, also it allows you to hang it somewhere. Hence the handle serves for more than one purpose.

Similar to this, API has more than on use cases and functionalities.

Scenarios where we need API

  1. Bolt on strategy - Add API to existing functional system, it is a brute force approach, but not very efficient.

  2. Greenfield Strategy - No underlying application, do whatever you want, in way you want, you start from scratch, requires massive investment

  3. Facade strategy
    Take advantage of existing business systems, replace piece by piece.

Good modelling of an API

  1. Don't worry about the tools (keep and take notes)
  2. Have a consistent process (document things nicely)
  3. It does not count unless its written down Documentation is non negotiable

Steps of designing an API

  • Identify participants (takes or receives action)
  • Identify Activities
  • Break into steps
  • Create API definitions
  • Validate API

HTTP VERBS

  1. GET - to retrieve data
  2. DELETE - delete data
  3. PUT - Update existing record
  4. POST - create new records

API Relationships

  • Independent : can exist on its own without any resources
  • Dependent : can only exist if other resource exists
  • Associative : can be dependent or independent but needs additional information to describe it

Validate an API

  • Step through each API call
  • Write code as if an API call exist (Use a microservices) (List endpoints, parameters)
  • Look for gaps and potential issues

Thanks for reading <3

Top comments (0)