Config-based API server framework
To see what the framework can do, let us try creating a simple API server. Here are the steps to create a simple API server that stores blog post data.
$ npm install --save orion-api
module.exports =
{
database:
{
dialect: "mssql",
host: _DATABASE_HOST_,
name: _DATABASE_NAME_,
userName: _DATABASE_USERNAME_,
password: _DATABASE_PASSWORD_
},
entities:
{
"blogpost":
{
"fields":
{
"title": { type: "string", isEditable: true, isRequired: true, foreignKey: null },
"content": { type: "richtext", isEditable: true, isRequired: true, foreignKey: null }
},
"permissions":
{
"read": ["guest"],
"create": ["guest"],
"update": ["guest"],
"delete": ["guest"]
}
}
}
}
Save the above file as config.js. Please see the Configuration Options page for more configuration options.
const Orion = require('orion-api');
const config = require('./config');
const orionApp = new Orion(config);
orionApp.setupApiEndpoints();
// You can add more endpoints to the orionApp.app object or do other things here
orionApp.startAsync();
$ node server.js
$
$ # insert a new blog post entry
$ curl -d '{"title":"I like trains", "content":"Trains are cool!"}' -H "Content-Type: application/json" -X POST http://localhost:1337/api/data/blogpost
$
$ # retrieve all blog post entries
$ curl http://localhost:1337/api/data/blogpost/public/findall/id/0/100
Go to API Endpoints page to see all of the endpoints that we provide.