Wrapping the Server in an API

The API layer has the following tasks to fulfill:

  • Insulate the server layer from inconsistent data and stitch together independent concepts from the individual GenServer implementations.

  • Hide internal implementations from the user, such as the Quiz struct we make available from our QuizManager server.

Any implementation details from server layers or the functional cores will be off-limits.

Similarities with OOP

Though our internal details may be radically different, the API-wrapped server will share many characteristics of an OOP object:

  • It will hide implementation details, including state, behind an API of functions.

  • It will allow complex interactions between components with message passing and will allow convenient state tracking.

Before we dive into the API, we’ll need some validations that assist us in our work. Let’s do that now.

Build validations

Validation is an automatic check to ensure that the data entered is sensible and feasible. When programming, it is essential that we include validation for data inputs. This stops unexpected or abnormal data from crashing our program and prevents us from receiving impossible garbage outputs.

drawing

Get hands-on with 1200+ tech skills courses.