REST API Red Flags Every Developer Should Know
We recently had a discussion as part of the “Out of the Box Developer” series on REST APIs, uncovering those sneaky “red flags” that can turn a smooth API experience into a developer’s nightmare.
Key Red Flags Every Developer Should Know #
Our conversation highlighted several critical areas where REST APIs commonly stumble. Understanding these is your first step to building robust and maintainable APIs.
1. The Verbs on Endpoint Names: A “Soapy” Inheritance #
One of the most immediate red flags discussed was the practice of using verbs directly in endpoint names, like /users/create
or /posts/get
.
The Insight: This is often a leftover from older “SOAP” service paradigms. RESTful principles dictate using HTTP methods (GET, POST, PUT, DELETE) to define the action and nouns for the resources.
Quote: “This kind of bad things happens and for that there is standards – those standards is very important because if we do not follow them, it’s really hard to move from a company to other or from a project to other…”
- Why it’s a red flag: It’s redundant and breaks the core REST principles. The HTTP method already communicates the action.
2. Overexposing Your Internals: The “Kitchen Sink” Approach #
Exposing too much information from your internal data structures or database entities to the API client is a recipe for trouble.
The Insight: Initially, developers might think, “I’ll just send everything, they might need it later!” But this leads to tightly coupled APIs that are hard to change. It’s much easier to add fields later than to remove them once clients are using them.
Quote: “I learned in the most difficult way how it is much difficult to take out anything from an object once you expose it on the API than the opposite when you have to add something more on the API…”
- The Solution: Use Data Transfer Objects (DTOs) to carefully design what data your API exposes. This separates your API contract from your internal implementation details.
3. Versioning: The Missing Link (or the Messy Link!) #
A lack of a clear versioning strategy, or a poorly implemented one, is a major red flag.
The Insight: As APIs evolve, you’ll inevitably need to introduce breaking changes. Without versioning, these changes can break existing integrations.
Quote: “We need to have versioning and this is another thing that it’s maybe a challenge to do this kind of thing to keep two versions and when you need to deprecated one of these versions and also remove this. So have a life cycle that’s hard to do.”
- Strategies to Consider:
- URL Path Versioning (e.g.,
/v1/users
): Most common and clear. - Query Parameter Versioning (e.g.,
/users?version=1
): Less common, but used by some. - Content Negotiation (Accept Header): Clients specify the desired response format.
- Custom HTTP Headers: Can be messy if not managed well.
- URL Path Versioning (e.g.,
4. The Documentation Void: “If it’s not documented, it doesn’t exist!” #
APIs without clear, up-to-date documentation are practically unusable.
The Insight: While Swagger/OpenAPI is a great start, it’s not enough on its own. Detailed descriptions, examples, and explanations are crucial for clients to understand and use your API effectively.
Quote: “Documentation is something that I’m always telling my students to have a good documentation. They usually only put the swagger there and they don’t configure anything don’t put more information.”
- Best Practice: Treat your API documentation as a vital part of your API, keeping it accurate and comprehensive.
5. Testing and Environment Neglect: The Production Gamble #
Improper testing strategies, especially relying on production or poorly configured test environments, are major red flags.
The Insight: Developers need a reliable way to test their APIs locally without impacting production.
Quote: “I know lots of people that use the production database or the stagin one to to test the the APIs instead of a mock. Maybe you should mock first and then try…”
- The Solution: Embrace mocking frameworks (like WireMock or libraries within your framework) and tools like Testcontainers for robust local testing and integration tests.
6. Weak Authentication and Authorization: The Open Door #
Insecure authentication and authorization mechanisms leave your API vulnerable.
The Insight: Not implementing proper security measures like OAuth, JWT, or API keys (depending on your use case) is a critical failure.
Quote: “If your API is exposed directly to the internet, you need to to have tokens to authenticating or O off or or something to to handle it in a proper manner. But usually that’s not the best architecture approach. Usually these days it will be much better to have an API gateway in front you of your of your applications…”
- Recommendation: Consider using an API Gateway for centralized authentication, rate limiting, and other security concerns.
7. The “Potency” Problem: Misusing HTTP Verbs #
Misunderstanding and misusing the idempotent nature of HTTP methods like PUT and DELETE leads to unexpected behavior.
The Insight: Idempotent operations can be called multiple times without changing the result beyond the initial application. PUT
should ideally update or create, while DELETE
should remove. Repeatedly calling DELETE
should have the same effect as calling it once.
Quote: “Delete and put, they must behave always the same, no matter how many times you call them.”
- The Pitfall: If a
DELETE
operation returns an error when the resource is already gone, or if aPUT
operation creates duplicates when called multiple times, you’re violating idempotency.
8. Input Validation: The Wild West #
Failing to validate incoming data is a direct path to errors and security vulnerabilities.
The Insight: Never trust client input. Always validate the format, type, and constraints of the data being sent to your API.
Quote: “You need to control what’s going into your application the format and what you’re expecting otherwise this can break. So that’s one of the biggest red flags you need to be aware.”
- Leverage Frameworks: Modern web frameworks often provide robust validation mechanisms (e.g., Bean Validation) that can be integrated seamlessly.
9. Scalability: Designing for the Future #
Not considering scalability from the outset can lead to performance bottlenecks down the line.
The Insight: While microservices and REST APIs are generally designed to be stateless, making them easier to scale, architectural choices can still impact performance under load.
Quote: “I never really thought about like the scalability when I’m building the API and I think this may this is maybe a red flag.”
- Key to Scalability: Embracing statelessness, leveraging containerization (like Docker and Kubernetes), and optimizing database interactions are crucial.
10. Hypermedia Controls (HATEOAS): Nice to Have, Not Essential #
While part of the mature REST principles (Level 3 of the Richardson Maturity Model), HATEOAS (Hypermedia as the Engine of Application State) is often misunderstood or over-engineered.
The Insight: Hypermedia involves including links in API responses that guide clients to available actions or related resources. While powerful in theory, it can add complexity and overhead without always providing significant benefits for many common API use cases.
Quote: “My answer is the short answer. No. And I don’t think in most of the case we need that. I really don’t think so. Usually it brings more it becomes more hard to maintain API and many many APIs does not take advantage on having the the hyperlinks.”
- The Trade-off: While good documentation and clear API design are paramount, implementing full HATEOAS might not be worth the effort for every API. Focus on the core functionality and maintainability first.
The Takeaway: Build Better APIs with Awareness #
Building great REST APIs is an ongoing learning process. By being aware of these common red flags, you can proactively design and implement APIs that are secure, scalable, maintainable, and a joy for other developers to use.
Remember, the goal is to build APIs that are not just functional but also well-documented, predictable, and adhere to established best practices. This not only benefits your consumers but also makes your own development life much easier!
Want to dive deeper? The brand new book “Mastering RESTful Web Services with Java” co-authored by Thiago Bomfim and Igor Fraga is available soon. Check out online to learn even more!