Skip to content

lucas-marquisio/simple-http-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Simple Http Api

SimpleHttpApi is a Node.js library that provides an uncomplicated approach to building HTTP servers with support for routes and middlewares. Developed in TypeScript and leveraging native http and url modules.

Features

  • Flexibility with Middlewares
  • Detailed Request Logging [debugg]
  • Minimal Configuration for Quick Start
  • Event-Driven Request Handling

How Use

import { SimpleHttpApi } from 'simple-http-api'
const simpleHttpApi = new SimpleHttpApi();

// simpleHttpApi.enableRequestLogging(); enable logs 

simpleHttpApi.start(4000); // start at port 4000

Middleware Example

const middleware = (request, response, pass) => { 
  pass() // to Calls the next function/middleware in the chain
}
simpleHttpApi.useGlobal(middleware)

params and body

route params  $myRouteParams
default config for body json

Methods Http

simpleHttpApi.get('/', (req, res) => {
  simpleHttpApi.sendResponse(res, 200, {}); // response, statusCode, body
}, [middlewares]);
    
simpleHttpApi.post('/', (req, res) => {
  simpleHttpApi.sendResponse(res, 200, {}); // response, statusCode, body
}, [middlewares]);
    
simpleHttpApi.put('/', (req, res) => {
  simpleHttpApi.sendResponse(res, 200, {}); // response, statusCode, body
}, [middlewares]);

impleHttpApi.delete('/$id', (req, res) => {
  simpleHttpApi.sendResponse(res, 200, {}); // response, statusCode, body
}, [middlewares]);

About

a simple library http server

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published