0.1.5 • Published 2 years ago

ezapigen v0.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago