ezapigen

0.1.5 • Public • Published

EzAPIGen

EzAPIGen is a simple npm package intended to make it easy to make simple REST APIs (that only support GET requests for now :P, preliminary support for other HTTP request types is being implemented)

I'm very new to Node JS in general so please send me any feedback you have!

Github: Codehc/EzAPIGen

NPM: ezapigen

By Codehc#7786 on discord

Installation

Use the node package manager npm to install.

npm install ezapigen

Usage

First, require the server and the endpoint class:

import * as server from 'ezapigen';
import { Endpoint } from 'ezapigen/endpoint';

Once you have it imported, create a new endpoint:

// Register new endpoint
const repeatEndpoint = new Endpoint(server.HTTPRequest.GET, 'repeat', ['text'], (self, req, args) => {
    return {
        statusCode: 200,
        header: ['Content-Type', 'text/plain'],
        message: `${args.text} ${self.type}`
    }
});

Next, you register the endpoint and start the server:

server.registerEndpoint(repeatEndpoint);

// Start the server
server.listen('127.0.0.1', 8080);

You can now access your api by going to http://127.0.0.1:8080/repeat?text=anytext.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i ezapigen

Weekly Downloads

0

Version

0.1.5

License

ISC

Unpacked Size

6.06 kB

Total Files

6

Last publish

Collaborators

  • codehc