Fastify: Question: routes and route schema best practice?

Created on 21 Sep 2017  路  3Comments  路  Source: fastify/fastify

Do you have any guidance for best practice to setting up routes, specifically;

  1. _Route project/folder architecture:_ how to organise routes grouped by resource type under a 'routes' folder and best way to asynchronously load these into the app?

  2. _Route schema:_ should a single generic schema be shared across routes of the same resource type, with properties which are only relevant to some of these routes. For example, routes that do expect a query string in the request and those that don't? Alternatively, is it better to pass a schema specific to each single route?

question

Most helpful comment

All 3 comments

  1. organize your application by logical plugins, your unit of distributions between files are plugins, and those can be nested indefinitely. having a specific folder for "routes" does not scale well for complexity, you should follow the features of your application more. I tend to have a folder/plugin for users, carts, products, etc... We will be providing an example for this structure.

  2. your schema is the same if the data you are receiving/sending is the same. If it's different data it should be different schemas. JSON schema is very flexible and you can reuse some part of your schema between different routes.

@mcollina, point 1 sounds sensible - do you have an ETA for your example app and perhaps link to watch?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

b4nst picture b4nst  路  3Comments

valentinvichnal picture valentinvichnal  路  3Comments

aaronshaf picture aaronshaf  路  3Comments

PacoDu picture PacoDu  路  3Comments

jsumners picture jsumners  路  4Comments