2.2.1 • Published 6 months ago

@tws-js/server v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

TWS - Type-Safe Web Server Framework

Test NPM

This framework was created with the purpose of enhancing the developer and user experience when developing and communicating with strongly typed APIs.

Usage

Installation

npm install @tws-js/server

Example

Start the server:

import { Operation, Schema, HTTPServerHelper } from '@tws-js/server';

const schema = new Schema({
  hello: new Operation({
    input: {
      name: {
        type: 'string',
        required: true,
        description: 'The name to greet',
      },
    },
    output: {
      type: 'object',
      properties: {
        message: {
          type: 'string',
          description: 'The greeting message',
        },
      },
    },
    handler: ({ name }, metadata) => { // "name" automatically typed as string
      return {
        // Typescript will warn if "message" is not a string,
        // as required by the output
        message: `Hello ${name}`,
      };
    },
  }),
}, {
  logger: {
    error: (message) => console.error(message),
  },
  enablePlayground: true,
});

HTTPServerHelper.create({
  port: 3000,
  schema,
  path: '/tws',
});

Send a request to the server:

curl -X POST \
  http://localhost:3000/tws \
  -H "Content-Type: application/json" \
  -d '{ "operation": "hello", "input": { "name": "TWS" } }'

Check the response:

{
  "data": {
    "message": "Hello TWS"
  }
}

Collaborating

Setup

nvm use 20
npm install

Running

npm start

Testing

npm run lint
npm test
2.2.1

6 months ago

2.2.0

6 months ago

2.1.0

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago