Chapter 5: The 8 Step Recipe
In this chapter, we will take what we learned in chapters 3 and 4, and combine them into what I call a 7 (+3) step recipe to creating any API endpoint.
We'll be extending the layered architecture as discussed previously by going over the middleware layer, the validation layer, and the event layer in this chapter.
But wait… what is this extra +3 step in the brackets? This is an extra 3 sub-steps that do not pertain to building the actual endpoint itself, but rather help solidify and strengthen your endpoint if you so choose to add it. The 3 sub-steps are Test, Refactor, and Document.
For simplicity sake, let's just group those last 3 sub-steps in 1 step, and call this "The 8 Step Recipe" from this point forward.
This 8 step recipe is essentially a formal design document, its purpose is to help you plan out your API endpoints before writing any code. It's a checklist of considerations when designing each layer of your endpoint. Think of this as a nice starter template for helping you to design and structure your endpoint and codebase.
This is the 7 (+3) step process that I have been using for the last 5+ years of my career and is something that has not only benefited me during solo projects, but it has also benefited many of the teams I have worked on when using this approach.
Here are some key benefits from using my 8 step recipe.
It takes away the anxiety and pressure of feeling like you might be missing something because it gives you a list of common considerations to think about beforehand.
Having a structured approach keeps you level-headed and clear about the design and structure of your API and code.
Having a methodical way of planning your endpoint let's you break the problem down and see where and what you need to work on.
You remember what you were thinking because you wrote it down; you can then reference it later.
Not only do you have a better understanding of the API endpoint, your team members will understand your thought process as well.
It will save you a ton of time (trust me), which means less tech debt in the future.
Here… is the 8 step recipe to creating any API endpoint.
Route Name (URI)
Input Request
Middleware
Validation
Business logic
Events
Output Response
Test, Refactor, Document
We will be going over each concept carefully in this chapter, and I will be explaining briefly what each component is and go over some real world applications. In the next chapter, we will begin to apply these concepts in building our web API.
This model or concept can be applied to any framework or language. This is supposed to be a framework and language agnostic blueprint so that you may apply this to any project you work on in the future.
Last updated