Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.87 KB

Readme.md

File metadata and controls

65 lines (50 loc) · 1.87 KB

Hiroki NPM version CircleCI

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