@splashprotocol/backend
TypeScript icon, indicating that this package has built-in type declarations

1.0.14 • Public • Published

Backend development kit

Package to create easy node.js services

Install

Run the following command:

// npm
npm i @splashprotocol/backend
// yarn
yarn add @splashprotocol/backend

Create backend route

Each route has 2 section: info and handler.

Info explanation

info includes

metadata

This refers to metadata or configuration associated with a specific route in your application.

It includes details such as:

The HTTP method (e.g., GET, POST).

The path (e.g., /users/{id}).

Parameters (query, path, headers, body).

Expected response type.

Swagger Specification:

The route info is used to generate OpenAPI/Swagger documentation.

This documentation describes the API's structure, including:

Endpoints.

Input parameters (query, path, headers, body).

Expected responses.

Zod Types for Validation:

Zod is a TypeScript library for schema validation.

The route info includes Zod schemas to validate:

  1. Query parameters.
  2. Path parameters.
  3. Headers.
  4. Request body.
  5. Return type

This ensures that incoming data matches the expected format.

Handler explanation:

function that receives checked parameters and returns result

Example:

export const launchRoute = Route.new({
    info: {
        route: '/launch',
        result: {
            status: 200,
            content: z.object({
                hello: z.string()
            })
        },
        body: {
            contentType: 'multipart/form-data',
            fileSizeLimit: 1024 * 1024,
            payload: z.object({
                image: zodFile( ['image/png', 'image/jpg', 'image/jpeg', 'image/gif']),
                info: z.string()
            })
        },
        tags: ['Launch'],
        summary: 'test',
        method: 'post'
    },
    handler: async ({ body, requestWorker }) => {
        return  await requestWorker<LaunchParams, LaunchResult>({
            type: 'launch',
            hello: '123'
        });
    }
})

Create backend:

example:

const backend = Backend.new({
    routes: [
        launchRoute
    ],
    settings: {
        maxBodyLength: 50 * 1024 * 1024,
        swaggerPath: __dirname,
    },
    info: {
        title: 'test',
        description: 'tes',
        version: '1.0.0',
    },
    environment: config
})
backend.run(3000);

Readme

Keywords

none

Package Sidebar

Install

npm i @splashprotocol/backend

Weekly Downloads

6

Version

1.0.14

License

none

Unpacked Size

109 kB

Total Files

22

Last publish

Collaborators

  • ridel1e
  • splash-trade