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

@worldsibu/conv-rest-api

v0.1.5

Published

Rest API generator for the Convector Framework

Downloads

5

Readme

conv-rest-api

This project is under development and will soon be integrated into the Convector CLI.

This project aims to provide an easy way for generating automatically client API for Convector projects.

How to use

To generate an API, you first need a Convector CLI generated project. Since the conv-rest-api is based on the Convector CLI standards and conventions, so manually projects generated may not work with it.

In the root of your project create a json file called api.json. This structure will map the smart contract to the Express API.

[
    {
        "function": "<function-name>",
        "controller": "<controller-class-name>",
        "verb": "get|post|put|delete"
    },
    {
        ...
    }
]

Example

If your smart contract project has the following structure:

  • ./packages/participants/src/participant.controller.ts
  • ./packages/person/src/person.controller.ts

And the controller files look like this:

participant.controller.ts

@Controller('participant')
export class ParticipantController extends ConvectorController {
  get fullIdentity(): ClientIdentity {
    const stub = (BaseStorage.current as any).stubHelper;
    return new ClientIdentity(stub.getStub());
  };

  @Invokable()
  public async register(
    @Param(yup.string())
    id: string,
    @Param(yup.string())
    name: string,
  ) {
      //...
  }
}

person.controller.ts

@Controller('person')
export class PersonController extends ConvectorController<ChaincodeTx> {
  @GetAll('Person')
  @Invokable()
  public async getone(
    @Param(Person)
    id: string) {
        // ...
  }
  @Create('Person')
  @Invokable()
  public async create(
    @Param(Person)
    person: Person
  ) {
      // ...
  }
}

Then your api.json

[
    {
        "function": "register",
        "controller": "ParticipantController"
    },
    {
        "function": "create",
        "verb": "post",
        "controller": "PersonController"
    },
    {
        "function": "getone",
        "verb": "get",
        "controller": "PersonController"
    }
]

Once that's ready, globally install the conv-rest-api util and generate your API!

Beware that it will remove and recreate a folder in your root ./packages/ folder called server.

npm i -g @worldsibu/conv-rest-api

# Inside your Convector CLI generated project's root
conv-rest-api generate api -c <chaincode-project-name> -f ./<chaincode-config-file>
# I.e.: conv-rest-api generate api -c person -f ./org1.person.config.json

# Compile everything
[npx] lerna bootstrap

# Start the server
[npx] lerna run start --scope server --stream

Support

  • For recommendations, feature requests, or bugs go to our issues section.
  • News on Convector, subscribe to our Newsletter.
  • Need support? Chat directly with our team and the growing community, join our Discord.

Contributions

Special thanks to Luca Tamburrano for starting this amazingly useful project for the community.