-
Notifications
You must be signed in to change notification settings - Fork 28
Home
The typescript-hapi-starter project was built with the intention to simplify the way we develop APIs. Also, it's intended to provide different branches that provides a set of integrations with different data stores, like SQL databases through Sequelize, NoSQL databases like MongoDB through Mongoose, and a last one where we provide a basic GraphQL API.
There's also a set of core concepts that we try to implement in the starter, and here we'll document it. The kit provides a set of abstractions like:
- Model
- Repository
- Resolver
- Service
- Controller
- Route Validator
The model is a description of a shape with its properties. In our case, the model should match the SQL Table or a MongoDB/NeDB Collection specification.
NeDB Model E.G.
class User {
public name: string;
public lastName: string;
}
The repository wraps the model usage. It's main responsibility is to provide a set of base operations that let you do more complex operations.
The resolver is similar to the DAO pattern, It's main responsibility is to use different repositories objects if needed to perform complex queries.
The service provides a top level abstraction over the resolver. It's main responsibility is to use Resolvers to resolve business centric logic.
The controller takes a request and response object, and perform transformations over the incoming data by the usage of services.
The route validator is a simple module exporting an object that contains Joi definitions to perform checks over the request params/query/payload/headers.