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

esx-rs

v0.1.6

Published

ECMAScript decorators for REST endpoint declaration, inspired by JAX-RS.

Downloads

15

Readme

ESX-RS

AppVeyor CircleCI Travis CI AppVeyor tests Codecov Code Climate Code Climate

Dependencies Development dependencies Known Vulnerabilities Greenkeeper

A library inspired by JAX-RS, allowing the description of REST endpoints through simple TypeScript decorators.

It has currently been integrated with:

| Integration | Type | Description | |:--------------------------------------------------------------------------|:-----------|:-----------------------------------------------------------------------------------------------------------| | esx-rs-client | Client | Proxy generator to access remote ESX-RS endpoints through a class instance. | | esx-rs-client-angular | Client | esx-rs-client network transport based on Angular HttpClient. | | esx-rs-client-fetch | Client | esx-rs-client network transport based on Fetch. | | esx-rs-client-http | Client | esx-rs-client network transport based on Node http. | | esx-rs-client-xhr | Client | esx-rs-client network transport based on XMLHttpRequest. | | esx-rs-server | Server | Dispatch incoming HTTP requests to ESX-RS decorated class methods. | | esx-rs-router-express | Server | esx-rs-server-based router middleware for Express. | | esx-rs-router-koa | Server | esx-rs-server-based router middleware for Koa. | | esx-rs-validation | Validation | Validation layer based on es-validation. | | esx-rs-schema-openapi | Schema | Schema generation for OpenAPI 3.0. |

Getting Started

The library can be installed using npm:

npm install esx-rs --save

Or using yarn:

yarn add esx-rs

Endpoints can then be described using decorators:

@Path('/users')
@Produces('application/json')
@Consumes('application/json')
class UsersEndpoint {

    @POST
    async createUser(user: User): Promise<User> {
        // ...
    }

    @PUT @Path('/:userId')
    async updateUser(@PathParam('userId') userId: string, user: User): Promise<User> {
        // ...
    }

    @GET @Path('/:userId')
    async getUser(@PathParam('userId') userId: string): Promise<User> {
        // ...
    }

    @DELETE @Path('/:userId')
    async deleteUser(@PathParam('userId') userId: string): Promise<void> {
        // ...
    }

}

Usage

Various decorators are available, each targetting a subset of the typical REST properties for a service.

Method

The HTTP method(s) can be specified using:

  • @DELETE
  • @GET
  • @HEAD
  • @OPTIONS
  • @PATCH
  • @POST
  • @PUT
  • @HttpMethod

Path

The resource path can be specified using:

  • @Path

Note: the path-to-regexp format is used, e.g. /path/to/:resourceId/subpath/:subresourceId.

Resource Type

The type of resource, either consumed by the operation (mapped to content-type) or produced by the operation (mapped to accept), can be specified using:

  • @Consumes
  • @Produces

Multiple media types may be specified.

Parameters

Operation parameters and resource properties are mapped using a specific decorator for each parameter type:

  • @CookieParam
  • @FormParam
  • @HeaderParam
  • @MatrixParam
  • @QueryParam
  • @PathParam

Context

It is also possible to map the following context information to a parameter using the @ContextParam decorator:

  • HttpContext
  • HttpRequest
  • HttpResponse

Endpoint vs. Operation

Many decorators can be applied to both a class and its methods.

In this scenario, the OperationInfo object returned for a method contains merged information that includes both the operation and the endpoint information.

The following decorators can be applied to both classes and methods:

  • @DELETE, @GET, @HEAD, @OPTIONS, @PATCH, @POST and @PUT
  • @Consumes and @Produces
  • @Path

The @Path decorator is handled a bit differently: the operation path is appended to the endpoint path.

Limitations

At the moment, only concrete classes can be decorated.

This is due to the way ECMAScript gets generated, as interfaces no longer exist in the generated code.