New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@delysium/api-kit

Package Overview
Dependencies
Maintainers
4
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@delysium/api-kit

API utility KIT for Express

  • 0.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-57.89%
Maintainers
4
Weekly downloads
 
Created
Source

@delysium/api-kit

Utility KIT for Express apis.

Installation

npm i @delysium/api-kit

Usage

  • Add Error middleware to your App
import express from "express"

const app = express()
app.use(errorMiddleware)
  • Declare API handler in your routes, removing Express from your Controllers logic
import {Router} from "express"
import {handle} from "../interfaces/api"

// your own controller
import UserController from "../controllers/user.controller"
import {validateRequest} from "../middleware"
const ctrl = new UserController()

const router = Router()
router.get("/users/:userId", handle.bind(ctrl.get))
router.post("/users", validateRequest(CreateRequest), handle.bind(ctrl.create))

export default router
  • Add routes to your App
import userRouter from "./routes/user.route"
app.use(userRouter)
  • Create your Controllers
    • You can now consider your controllers as simple methods without considering Express anymore
    • The success response will be handled in the router and the possible errors will be handled by the error middleware when HttpException are thrown in your code
import {PathRequest, AuthBodyRequest} from "../interfaces/api"

export default class UserController {
    public get = async (req: PathRequest<GetRequest>): Promise<UserResponse> => {
        const params = req.params
        return {}
    }
    public create = async (req: BodyRequest<CreateRequest>): Promise<UserResponse> => {
        const body = req.body
        return {}
    }
}

Keywords

FAQs

Package last updated on 21 Dec 2022

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