For Juniors and Frontend Developers: Usable and Maintainable API Design

Ali Murat Umutlu
5 min readJul 9, 2024

--

Title may be confusing but if you are a Frontend developer who is curious about API development, this article will be so helpful to you.

I have worked with many APIs during my career. Some of them were 3rd party APIs, and some were our own projects. For Frontend Developers, working with a poorly-structured API can sometimes be painful. If you want to build an API, you must ensure its usability. That’s why I want to share my experience and knowledge stored in Apple Notes with you.

If these titles caught your attention, you likely already know what an API is. Their main role is enabling different software systems to communicate with each other. But why is their structure so important?

1. Usability & Maintainability

Because we’re human beings. Both usable and maintainable API design is crucial for ensuring team members understand the logic easily and work efficiently. This is the key to long-term success and scalability for growing projects.

Today’s Plan: Usability

Usability in API design refers to how easily developers can understand and use the API. It is totally about the actual usage. While planning a strategy it will be related about the efforts that needs to be done asap. A usable API is supposed to have:

  • Clear Documentation: Comprehensive and easy-to-understand documentation.
  • Consistency: Consistent naming conventions and structures.Intuitive Design: Logical and predictable behavior.
  • Error Handling: Clear and helpful error messages.

Being Ready for the Future: Maintainability

Maintainability can be understood as how easily the API can be updated and extended over time without causing issues for existing users. A maintainable API should have the following features:

  • Versioning: Strategies to manage changes and updates.
  • Modularity: Separation of concerns and reusable components.
  • Backward Compatibility: Ensuring new changes do not break existing functionality.
  • Testing: Comprehensive test coverage to ensure reliability.

2. Best Practices for Usable APIs

I think examples from real life would be more helpful than theories. Let’s give some examples then:

a. Clear and Consistent Naming Conventions

Adopting clear and consistent naming conventions helps users understand the API without extensive documentation.

Follow industry standards and conventions, such as using nouns for resources (e.g., /users, /orders) and HTTP verbs for actions (e.g., GET, POST, PUT, DELETE).

No need to use getAllUsers or getUserById etc. Keep it simple as it can be.

/users

/users/123

These 2 base URL will be enough for all sort of api calls. In this style, we keep verbs out of the base URLs. Actions (GET, POST, PUT, PATCH, UPDATE, DELETE) do the remaining work for us.

What if there is a relation with another collection. If we want to list all users from a company:

/companies/1234/users

That will help developers to understand the logic behind the whole API.

If you are really willing to learn more about the naming conventions, I have a book advice for you: Web API Design: Crafting Interfaces that Developers Love (Brian Mulloy)

b. Comprehensive Documentation

Documentation is also essential for usability. Tools like Swagger (my choice) or Postman Collections can help you to create interactive and user-friendly documentation. While creating a documentation, you must ensure the followings:

Overview: General information about the API and its purpose.

Endpoints: Detailed descriptions of each endpoint, including parameters, request/response examples, and error codes.

Authentication: Clear instructions on how to authenticate requests.

Examples: Practical examples and use cases.

c. Consistent and Predictable Behavior

Design the API to behave consistently across all endpoints. For example, always return the same response structure for similar operations (REMEMBER NAMING CONVENTIONS ABOVE) , and use standard HTTP status codes. This predictability reduces the learning curve for users.

d. Thoughtful Error Handling

Your code must have some standards. Provide meaningful error messages and codes:

Avoid generic errors like 500 Internal Server Error without context.

Use totally descriptive messages and include helpful information, such as error types, details, and possible solutions.

e. API Versioning

That is also important issue. If you are working for a startup, there is a big possibility for API updates. In that case implement versioning to manage changes without disrupting existing users.

Common approaches include:

URI Versioning: Include the version number in the URI (e.g., /v1/users).

Header Versioning: Specify the version in request headers (e.g., Accept: application/vnd.api.v1+json).

These best practices are some that I really liked in the projects that I worked.

3. Best Practices for Maintainable APIs

Now let’s see some theoric information to ensure the maintainable APIs.

a. Modularity and Separation of Concerns

Design the API with modularity in mind.

Break down functionality into smaller, reusable components. This approach simplifies maintenance and enables easier updates and testing.

I really like and appreciate the service oriented structure.

b. Automated Tests

Implement automated testing for all aspects of the API, including unit tests, integration tests, and end-to-end tests. Testing ensures that changes do not introduce bugs and helps maintain reliability.

c. Backward Compatibility

Ensure new updates do not break existing functionality. Use versioning and provide clear deprecation policies. Communicate changes to users and give them ample time to migrate to newer versions. (Demo meetings with the devs would be useful)

d. Scalability and Performance

Design the API to handle increasing loads and performance demands.

Optimize database queries, use caching where appropriate, and consider rate limiting to protect against abuse.

Below you will see a Node server code that uses Redis for caching. In this example, user data is cached to reduce the load on the MongoDB database. When a request is made, the API first checks the Redis cache. If the data is found, it is returned immediately. If not, the API fetches the data from MongoDB, stores it in Redis, and then returns the response.

The server also has a rate-limit to block abuse usage. The rate limit will limit the number of requests an IP can make to the API within a specified time window.

You can learn more info about the Redis Server hosting on AWS: https://aws.amazon.com/tr/getting-started/hands-on/boosting-mysql-database-performance-with-amazon-elasticache-for-redis/module-one/

e. Security

Security is a critical aspect of API design. Implement robust authentication and authorization mechanisms. Use HTTPS to encrypt data in transit, and validate all inputs to prevent injection attacks.

As security is really big issue, I will try to explain it in a dedicated article.

Hope you have found this article useful! Investing time and effort into designing high-quality APIs will really pay off by reducing support and maintenance costs, increasing developer satisfaction, and enabling your platform to scale effectively.

Warm Regards!

--

--