1.0.14 • Published 11 months ago

@splashprotocol/backend v1.0.14

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

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);
1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago