API End Points
Shutterstock

API End Points

In recent years, there has been a paradigm shift towards Microservices. Together with Domain Driven Design, it provides a good technique to develop complex enterprise wide business functionality. Of course, there are numerous challenges in both these techniques that require skill and patience (at times) to achieve the end result.

Irrespective of a technique or framework, the most important aspect of any large scale application is its 'modelling'. This includes modelling of API, domain, database, etc. Of particular interest to me is the API design. I have noticed that unless you design public APIs, teams don't give too much importance to this topic. As functionality gets developed across the client - server architecture, APIs are built more like 'raw' Remote Procedure Calls (RPC). Every API is meant to be be invoked from 'your own' client at a 'known' point in time. Hence, there is an implicit coupling built between your client and server components. In other words, it can be very difficult or just impossible to build a new client to consume your services.

The most common and fatal mistake developers tend to do is to 'leak' implementation details of a service through the API interface. In other words, they design API interfaces more as ways to implement technical tasks rather than fulfilment of functional needs.

For example, let's assume you are building a service to enable a 'buyer' evaluate his 'vendors' each day. Vendors can make submissions one or more times a day. The buyer then evaluates the submissions and selects a vendor each day. The following could represent a set of RESTful API end points for this requirement:


Say, there is a new requirement to exclude a vendor's submission during evaluation. Also, it should be possible to undo this exclusion.

The first naive attempt is to implement the requirement as shown:

The API doesn't reveal the business intention clearly to a consumer. We are asked to exclude a vendor's submission explicitly. Can we not create a new end point that represents this requirement ?

We now have two end points leveraging the HTTP POST and DELETE methods - one for exclusion and the other for undo exclusion.

By thinking in terms of the business functionality, the end point has become more meaningful than just a projection of a technical implementation. Writing APIs that leak the internal technical implementation/state can make it difficult to understand and maintain them. They also increase the coupling between client and server components making them less independent and flexible.

Each end point should have a business meaning in your application. Here are a few points to enable cleaner API design and modelling:

1. Think in terms of business actions; not the underlying state based actions in your client - server implementation
2. Create end points with single responsibility; the underlying logic can still be reused across end points
3. Separate end points for each user role if it aids better clarity

In my next blog, I will describe similar issues when building an API based client server workflow application.

Murali Krishnan Mani

Technical Program Manager at Google

9 年

Good one Shivsu

回复

要查看或添加评论,请登录

Sivasubramanian V的更多文章

  • Applying Systems Thinking to decode Disruptive Innovations

    Applying Systems Thinking to decode Disruptive Innovations

    In his seminal book "The Innovator’s Dilemma", Clayton Christensen lays out a conceptual model to predict whether…

    2 条评论
  • 3 Underrated Leadership Qualities

    3 Underrated Leadership Qualities

    To lead people effectively demands a diverse set of qualities in leaders. It includes integrity, accountability…

    2 条评论
  • Leadership Lessons: Carrot and the Cheese

    Leadership Lessons: Carrot and the Cheese

    Only few initiatives in an organisation become successful. Many get dropped mid-way while some don't even take off.

    10 条评论
  • Leadership Lessons: Ask, don't tell !

    Leadership Lessons: Ask, don't tell !

    The first learning for many young leaders could actually arise out of well - sheer frustration ! It occurs when tasks…

    1 条评论
  • Refactoring - Common Misconceptions

    Refactoring - Common Misconceptions

    Code refactoring is an integral activity of every developer's day to day routine. It is a disciplined technique that…

    2 条评论
  • Tilting the balance with tests

    Tilting the balance with tests

    Early last year there was a buzz on whether Test Driven Development (TDD) was really being productive or otherwise. A…

  • Building a RESTful Workflow application

    Building a RESTful Workflow application

    Complex business applications include a workflow processing of some sorts. It could vary from being a light weight…

  • The art of building features incrementally !

    The art of building features incrementally !

    Ever since my first Agile project 5 years back, I have been fascinated with the approach of building any [big]…

    1 条评论
  • Dare to think beyond a developer !

    Dare to think beyond a developer !

    Developers part of XP (Extreme Programming) teams are special. They posses lot of knowledge and skill to solve problems…

    2 条评论
  • Incremental Design and Evoluationary Architecture in Agile development

    Incremental Design and Evoluationary Architecture in Agile development

    I have been coding in XP ways for the past few years. I have realised that in any Agile project that runs for more than…

    2 条评论

社区洞察

其他会员也浏览了