npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pinup

v1.1.12

Published

Pinup is a library that enables you to create simple and efficient REST APIs in TypeScript using the Express framework.

Downloads

27

Readme

Pinup - Creating REST APIs Made Easy

Pinup - Creating REST APIs Made Easy

npm version npm downloads

Pinup is a library that enables you to create simple and efficient REST APIs in TypeScript using the Express framework. The library provides a set of tools and decorators that allow you to define API endpoints in a modular and readable manner.

Installation

To get started with the Pinup library, you can install it using the npm package manager:

npm install pinup

Use also pinup-cli to generate whole projects
Instalation:

npm install -g pinup-cli

Creating:

pinup create <name> [options]

Quick Start

Here's a simple example of using the Pinup library to create two API endpoints:

import express from 'express';
import { Pinup, Pinpack, reply, pin, pins, need } from 'pinup'

const app = express();
const pinup = new Pinup(app);

@pin('dogs')
export class DogController {
    @pins.get()
    getDogs({ op }: Pinpack) {
        const dogs = ['Bulldog', 'Poodle', 'Labrador']
        return op.pin.res(reply().data(dogs))
    }

    @pins.get(':id')
    @need.params(['id'])
    getDogById({ op }: Pinpack) {
        const dogId = op.params.id
        const dog = { id: dogId, breed: 'Bulldog' }
        return op.pin.res(reply().data(dog))
    }
}

pinup.run();

Features

Decorators

  • @pin('endpoint'): Creates a new controller handling endpoints at the specified endpoint.
  • @pins.method('path'): Decorator for HTTP methods (e.g., @pins.get(), @pins.post('new')) attaches handling functions to endpoints.
  • @need.param(['param1', 'param2']): Requires specific parameters in requests for further processing.
  • @auth(): Requires JWT authentication for accessing the endpoint.

Class Pinup

The Pinup class is used for configuring and running the Express application.

  • new Pinup(app: express.Express, config?: PinupConfigType): Creates a Pinup instance.
  • setup(): Configures endpoints and controller paths.
  • run(logger?: boolean): Launches the Express server.

Function reply

The reply Monad is responsible for creating and sending responses from endpoints.

  • reply(content: string | Pinres): Creates a response instance.
  • Chainable Methods:
    • status(status: number): Sets the response status.
    • error(error: boolean): Sets the error flag.
    • timestamp(timestamp: number): Sets the timestamp.
    • path(path: string): Sets the response path.
    • data(data: { [index: string]: any }): Adds data to the response.
    • map(callback: (item: Pinres) => Pinres): Maps the response using a provided function.

Usage Example

import express from 'express';
import { Pinup, Pinpack, reply, pin, pins, need } from 'pinup'

const app = express();
const pinup = new Pinup(app);

@pin('items')
export class ItemController {
  @pins.get()
	getItems({ op }: Pinpack) {
		const items = ['item1', 'item2', 'item3']
		return op.pin.res(reply().data(items))
	}

  @pins.get(':id')
  @need.params(['id'])
  getItemById({ op }: Pinpack) {
  	const itemId = op.params.id
  	const item = { id: itemId, name: 'Sample Item' }
  	return op.pin.res(reply().data(item))
  }
}

pinup.run();

In the above example, a controller handling endpoints '/items' and '/items/:id' is created. The @pins.get() and @pins.get(':id') decorators specify supported HTTP methods and paths.

Contribution

If you want to contribute to the Pinup project, go ahead! I have an open repository on GitHub where you can report issues and submit pull requests: Pinup Repository on GitHub