1.1.0 • Published 7 months ago

@danny270793/tsframework v1.1.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
7 months ago

TSFramework

TSFramework is typescript microframework for an educational porposes

Instalation

Install package from public registry

npm install @danny270793/tsframework

Example

Import the library

import { TSFramework, Router, Request } from '@danny270793/tsframework'

Create how many routers you need

const apiRouter: Router = new Router()

Register a callback for the path /users/:user_id/location/:location_id just for get requests Notice that the callback must return something, the framework serializes that return to json automatically before sent it back to the client

apiRouter.get(
    '/users/:user_id/location/:location_id',
    async (request: Request<any>): Promise<Request<any>> => {
        return request
    }
)

Create a TSFramework instance and set it the router with a prefix, then run the web server in an specific port

const port: number = 8000
const app: TSFramework = new TSFramework()
app.set('/api', apiRouter)
app.run(port)

Test the library

curl -X GET http://127.0.0.1:8000//users/25/location/35?key1=value1&key2=value2

Follow me

LICENSE

Licensed under the MIT License

Version

TSFramework version 1.0.0

Last update 09/03/2023

1.1.0

7 months ago

1.0.0

1 year ago