Skip to content

MVC

This page is a guide to use the MVC pattern with Byte.

Controllers

Every Byte instance is equivalent to a controller.

// Don't do this
app.get('/', Controller.index);
// Do this instead
app.get('/', (ctx) => {
// Write the handler code here
// Does not require manual typings
});

Services

Some piece of code that can be decoupled from the controller should be separated into a service:

export const getNumbers = query.get('number', {
type: 'number',
maxItems: 5000
});

Models

Models can be handled using states in Byte:

export const validateBody = Byte.handle((ctx) => {
// Return a result or a Response object
});