Skip to content

golibnarzullayev/huno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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