1.0.4 ā€¢ Published 29 days ago

@tws-js/server v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
29 days ago

TWS - Type-Safe Web Server Framework

Test NPM

āœ… 100% code coverage

Usage

Installation

npm install @tws-js/server

Example

Start the server:

import { Operation, Schema, createServer } 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}`,
      };
    },
  }),
});

const server = createServer({
  schema,
  path: '/tws',
  logger: {
    error: (message) => console.error(message),
  },
  enablePlayground: true,
});

server.listen(3000);

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 18
npm install

Running

npm start

Testing

npm run lint
npm test
1.0.4

29 days ago

1.0.3

29 days ago

1.0.2

10 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago