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

@gota/service

v0.0.7

Published

**Gota Framework** support developer build services base on **NodeJS** Environment and **TypeScript** language.

Downloads

3

Readme

Gota Framework!

Gota Framework support developer build services base on NodeJS Environment and TypeScript language.

Create A Service Class

Class Mapping

 function Service(mapping: {
    name?: string;
    path: string | Array<string>;
    config?: object;
    models?: Array<any>;
})
  • name: name of service, default is class name.
  • path: url(s) of service, default is Hyphen(Dash) case of class name. (https://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/)
  • config: dependency injection (more detail).
  • models: auto generate service (more detail).

Use decorator Service before a class.

Example:

@Service({path:'/user-service'})
export class UserService{
    ..........
}

Method Mapping

function ServiceMapping(mapping: {
    path: string | Array<string>;
    requestMethod?: string | Array<string>;
})
  • path: url(s) of service, default is Hyphen(Dash) case of method name.
  • requestMethod: method(s) GET | POST | PATCH | PUT | DELETE, default is GET

Use decorator Mapping before a method. Return data or Awaited data will be convert to JSON and response to client.

Example:

@Service({path:'/user-service'})
export class UserService{
	...
    @ServiceMapping({path: '/users'})
    async readAll():Promise<Array<User>>{
        ...
    }
    
}

Parameter Mapping

We use one of decorators: PathParameter, Body, BodyParameter, Query, QueryParameter, Headers, HeadersParameter, Request, Response before a argument of method. Framework will find and convert data before method execute.

PathParameter:

Mapping with url parameter. Start of PathParameter is ':' character.

...
    @ServiceMapping({path: '/users/:userId', requestMethod: 'GET'})
    async get(@PathParameter userId: string):Promise<User>{
        ...        
    }

PathParameter name in url (path: '/users/:userId') and argument name in method (userId: string) must be the same.

BodyParameter

Example:

...
    async create(@BodyParameter firstName : string, @BodyParameter lastName : string, @BodyParameter email: string, @BodyParameter phone: string):Promise<User[]>{
        let user: User = new User(firstName, lastName, email, phone);
        ...        
    }    
...

Framework will find parameters (firstName, lastName, email, phone) in request body and map with arguments in method by naming.

Body

Example:

...
    @ServiceMapping({path: '/users', requestMethod: 'POST'})
    async create(@Body body: object):Promise<String>{
        let user: User = new User(body.firstName, body.lastName, body.email, body.phone);
        ...        
    }    
...

Framework will collect all parameters in request body and map with a argument (has @Body decorator) in method.

Query, QueryParameter, Headers, HeadersParameter

(same with below cases)

Request

Framework will collect all information in request and map with a argument (has @Request decorator) in method.

Response

Framework will collect all information in request and map with a argument (has @Request decorator) in method.

Start A Service

...
    async create(@BodyParameter firstName : string, @BodyParameter lastName : string, @BodyParameter email: string, @BodyParameter phone: string):Promise<User[]>{
        let user: User = new User(firstName, lastName, email, phone);
        ...        
    }    
...

Dependency injection

Config

Autowired