🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

rest-but-less

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

rest-but-less

Rest API, less code

1.0.7
unpublished
latest
npm
Version published
Maintainers
1
Created
Source

rest-but-less: A Node.js Module for Creating RESTful APIs

rest-but-less is a lightweight and easy-to-use Node.js module designed to simplify the creation of RESTful APIs. With rest-but-less, you can quickly define endpoints for various HTTP request methods such as GET, POST, PATCH, PUT, DELETE, OPTIONS, and HEAD. It automatically handles injecting dependencies from POST data, URL parameters, or a service list, making API development a breeze. Easily switch between NodeJS & AWS Lambda!

Install

npm i rest-but-less

Features

  • Define RESTful endpoints using intuitive functions like get, post, patch, put, Delete, options, and head.
  • Automatically inject dependencies from POST data, URL parameters, or a service list into endpoint functions.
  • Supports various HTTP request methods for flexible API development.
  • Lightweight and easy-to-use, ideal for rapid development of RESTful APIs.

Getting Started

Import the rest-but-less module into your Node.js application:

import { useNode, get, post, patch, Delete, put, head, options, ResponseResult } from 'rest-but-less'

Define your endpoints using the provided functions:

// Define a GET endpoint
get('/users/:id', (id:number, db:unknown): Promise<ResponseResult> => {
    // Retrieve user data from the database using the provided id
});

// Define a POST endpoint
// userData is equivalent to POST.userData (or $_POST['userData'] for you PHP fans)
post('/users', (userData:Record<string,any>, db:unknown): Promise<ResponseResult> => {
    // Create a new user in the database using the provided userData
});

Inject dependencies into your endpoints using the service list:

import { addService } from 'rest-but-less';

// Add a service to the service list (e.g., a MySQL database connection)
addService('db', dbInstance);

// Access the service within endpoint functions
get('/users', (db) => {
    // Access the database connection (db) to retrieve user data
});

Starting a server (Node)

Starting a server is fairly easy.

Using AWS Lambda

import { useLambda } from 'rest-but-less'

export const handler = async (event, context) => {

    // load in routes prior....

    return await useLambda(event)
};

No HTTPS

import { useNode } from 'rest-but-less'

useNode({
    httpPort: 8080
})

With HTTPS

import { useNode } from 'rest-but-less'

useNode({
    httpPort: 8080,
    httpsPort: 443,
    httpsCertPath: 'path/to/cert.pem',
    httpsKeyPath: 'path/to/key.pem'
})

License

rest-but-less is licensed under the MIT License. Feel free to use, modify, and distribute it as needed.

Keywords

Rest

FAQs

Package last updated on 10 Feb 2024

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