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

@agape/api

v0.4.4

Published

Framework for building Rest APIs

Downloads

11

Readme

Agape API

Framework for building APIs

Synopsis

@Service()
class FooService {
    foo() {
        return { "message": "BARRRRGGHHHHH" }
    }
}

@Controller()
class FooController {

    constructor( public service: FooService ) {

    }

    @Get('foo')
    foo() {
        return this.service.foo()
    }
}

@Module({
    controllers: [FooController]
})
class FooModule() { }


const app: Application = express();
app.use( express.json() )
app.use( express.urlencoded({ extended: true }))

const router = Router()
bootstrapExpress(router, FooModule)

app.use('/api', router )

Summary

Model-View-Controller APIs

Application Components

There are three primary components to an API application. Modules, Controllers, and Services.

Controllers

Controllers respond to routed requests by interacting with services and returning a response to be sent back to the end user. The Controller class decorator is used to designate a class as a controller.

Class Decorator

Controller

Example
@Controller('path/to/controller')
class FooController {
    ...
}

Method Decorators

One method decorator for each HTTP request.

@Get(path)

@Post(path)

@Put(path)

@Patch(path)

@Delete(path)

@Status(code)

Set a custom success status code. Default is 200 OK.

@Get('teapot')
@Status(418)
teapot() {
    ...
}

@Respond(model)

Example
@Controller('foos')
class FoosController {

    @Get()
    list() {

    }

    @Post()
    create( params: undefined, body: IEvent ) {
        ...
    }

    @Get(':id')
    retrieve( params: { id: string } ) {
        ...
    }

    @Put(':id')
    update( params: { id: string }, body: IEvent ) {
        ...
    }

    @Patch(':id')
    update( params: { id: string }, body: Partial<IEvent> ) {
        ...
    }

    @Delete(':id')
    retrieve( params: { id: string } ) {
        ...
    }

}

Services

Services are injected into controllers and other services through the contstructor.

Declare a service using the Service decorator. Only one instance of a service is used across the entire application via dependency injection.

Class Decorator

Service

Example
@Service()
class FooService {
    
    foo() {
        ...
    }

}

@Service() 
class BarService {
    constructor( public foo: FooService ) {

    }
}

Modules

Modules contain one or more controllers. Controllers need to be declared in a module to be accessible through the API. Declaring a service as part of a module through the provides parameter is optional.

Class Decorator

Module

Parameters

controllers

modules

path

Example
@Module({
    'controllers': [ FooController ],
    'modules': [ BarModule ]
})

Requisites

You must have the compiler options experimentalDecorators and emitDecoratorMetadata set to true in your tsconfig.json file. This means that you cannot bundle with esbuild which does not support these compiler options.

See Also

Express

Author

Maverik Minett [email protected]

Copyright

© 2023 Maverik Minett

License

MIT