Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capujs/framework

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capujs/framework

A framework build declarative and beautifully organizated based in class controllers with decorators usage in Express.js

  • 0.0.3
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@capujs/framework

A framework build declarative and beautifully organizated based in class controllers with decorators usage in Express.js

Installation

Install with yarn

yarn add @capujs/framework

#install types
yarn -D add @types/express
yarn -D add @types/cors

Its important enable decorators in you project tsconfig.json

{
	"emitDecoratorMetadata": true,
	"experimentalDecorators": true
}

Example of usage

  1. Create file ExampleController.ts
import { Controller, Get } from "@capujs/framework";

@Controller("/example")
export class ExampleController {
	@Get("/")
	testMethod() {
		return "Hello Word";
	}
}
  1. Create app.ts
import { createServer} from '@capujs/framework';
import { ExampleController } from './ExampleController';

const app = createServer({
   controllers [ExampleController ]
});

//Listen express
const PORT = 3000;

app.listen(PORT,()=> console.log(`Server ready on port ${PORT}`);

Decorators Reference

Controllers
DecoratorExampleDescription
@Controller(prefix?: string)@Controller("/test") class TestControllerRegister class with this decorator a registred as controller and its anotated methods are registred. it using express `res.send()
Methods for Controllers
DecoratorExampleDescription
@Get(path?:string)@Get('/users') all()Method marked with this decorator register a request with GET method
@Post(path?:string)@Post('/users') save()Method marked with this decorator register a request with POST method
@Put(path?:string)@Put('/users/:id') update()Method marked with this decorator register a request with PUT method
@Patch(path?:string)@Patch('/users/:id') update()Method marked with this decorator register a request with PATCH method
@Delete(path?:string)@Delete('/users/:id') remove()Method marked with this decorator register a request with DELETE method
@Head(path?:string)@Head('/users/:id') head()Method marked with this decorator register a request with HEAD method
@All(path?:string)@All('/users/:id') all()Method marked with this decorator register a request with ALL method
@Options(path?:string)@Options('/users/:id') all()Method marked with this decorator register a request with OPTIONS method
Decorators for Parameters (inject in methods)
DecoratorExampleDescription
@Body(options?:IParamOptions)save(@Body() data: CustomDto)Inject a body an parameters options can using bodyParser middleware. using req.body
@BodyParam(name:string, options?:IParamOptions)save(@BodyParam('name') name:string)Inject a body an parameters options can using bodyParser middleware. using req.body.name
@Params()get(@Params() params: any)Inject all parameters req.params
@Param(name:string, options?:IParamOptions)get(@Param('id') id: string)Inject a query parameter req.params.id
@HeaderParams()get(@HeaderParams() params: any)Inject all parameters req.headers
@HeaderParam(name:string, options?:IParamOptions)get(@HeaderParam("authorization") authorization: string)Inject a header parameter req.headers.authorization
@CookieParams()get(@Cookies( cookies: any)Inject all cookies parameter req.cookies
@CookieParam(name:string, options?:IParamOptions)get(@Cookie("token") token: string)Inject a cookie parameter req.cookies.token
@UploadFiles(name:string, options?:IUploadOptions)post(@UploadFiles("photos") photos: any[])Inject multiple upload files from parameter req.files using middleware express-fileupload
@UploadFile(name:string, options?:IUploadOptions)post(@UploadFile("photo") photo: any)Inject single upload file from parameter req.files using middleware express-fileupload

Decorators for Middlewares

DecoratorExampleDescription
@Use(...middleware: RequestHandler[])@Use(isAuthenticated) class ProfileControllerRegister global middleware.

Decorators on Response

| Decorator | Example | Description | | :------------------------------------- | :------------------------------------------------ | :----------------------------------------------- | -------------------------------------------------- | | @HttpCode(code: number) | @HttpCode(201) signup() | Set custom http code after executing successfuly | | @OnNull(codeOrError: number | Error) | @OnNull(200) get() | Set a http code when controller return a null | | @OnUndefined(codeOrError: number | Error) | @OnNull(200) get() | Set a http code when controller return a undefined | | @Header(name: string, value: string) | @Header('Authorization','some-token') profile() | Set a http header after executing successfuly |

Keywords

FAQs

Package last updated on 17 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc