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.

  1. 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.

  2. Having a structured approach keeps you level-headed and clear about the design and structure of your API and code.

  3. 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.

  4. You remember what you were thinking because you wrote it down; you can then reference it later.

  5. Not only do you have a better understanding of the API endpoint, your team members will understand your thought process as well.

  6. 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.

  1. Route Name (URI)

  2. Input Request

  3. Middleware

  4. Validation

  5. Business logic

  6. Events

  7. Output Response

  8. 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