hiroki

2.0.0 • Public • Published

Hiroki NPM version Build Status

build REST APIs faster than ever using the open source tools and standards you and your team already know.

read the documentation here.

Getting Started

Step by step example Getting Starter.

Installation:

npm install --save hiroki

Create simple rest api:

this is a basic example, keep in mind you may need body-parser library.

const express = require('express');
const hiroki = require('hiroki');
const mongoose = require('mongoose');
const app = express();

// Model definition
const UsersSchema = new mongoose.Schema({name: String});
mongoose.model('Users', UsersSchema);

// Importing model
hiroki.importModel(UsersSchema);

// Bodyparser added
app.use(bodyParser.urlencoded());

app.use(bodyParser.json());


// Api route to pass data to hiroki
app.use('/api/*', async(req, res) => {
    const path = req.originalUrl;
    const resp = await hiroki.process(path, {
        method: req.method,
        body: req.body
    });
    res.status(resp.status || 200).json(resp);
});

app.listen(8012);

Build config:

it is possible to change the route that hiroki uses

hiroki.setConfig({ 
    basePath: '/api/v2' // default /api
});

Changelog

  • v2.0.0:
    • hiroki should be now backend agnostic. Express removed as dependency.
    • mongoose version updated
    • share will be removed for this version. Check if this would be usefull. Full Changelog

/hiroki/

    Package Sidebar

    Install

    npm i hiroki

    Weekly Downloads

    23

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    24.5 kB

    Total Files

    11

    Last publish

    Collaborators

    • percho