huno-server
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Installation

$ npm install huno-server

Usage example

import { HunoServer, sendJson, parseJsonBody } from 'huno-server';

const app = new HunoServer();

app.get('/', function ({ req, res }) {
  sendJson(res, { message: 'Hello Huno' });
});

app.post('/', async function ({ req, res }) {
  const body = await parseJsonBody(req);

  sendJson(req, body);
});

// using params
app.get('/:id', function ({ req, res, params }) {
  const id = params.id;
  sendJson(res, { id: id });
});

// using query params
// E.g.: url: http://localhost:3000?search=huno
app.get('/', function ({ req, res, query }) {
  const search = query.get('search');
  sendJson(res, { search: search });
});

app.start(3000);

Readme

Keywords

Package Sidebar

Install

npm i huno-server

Weekly Downloads

9

Version

1.0.7

License

MIT

Unpacked Size

14.4 kB

Total Files

16

Last publish

Collaborators

  • golibnarzullayev