Build a API Server
Introduction
info
Enterstarts API Gateway is not yet GA (Generally Available), this documentation aims to present the service only and serve as a reference point to exchange ideas and standardize the technical guides.
Please contact us if this solution is of interest and you have a urgent need.
The Enterstarts Platform boasts a full-featured, fast, secure and flexible api-gateway implementation. Unlike other offers the API Gateway support full code endpoints, you can create endpoints with standard http methods (GET, PUT, DELETE, etc) and just implement the handler in nodejs by using the expressjs framework and other included libraries in the api.
API Gateway applications are executed on the container system which takes care of provisioning, securing and managing dependencies at the container level.
Applications build with api-gateway come with high quality libraries to build integrated, mission critical, cloud native and modern applications.
Among other libraries, we include:
- momentjs
- underscore
- amqplib (rabbitmq)
- decimal.js
- ioredis
- node-fetch
- aerospike
- aws sdk
- nodemailer
Beside these libraries, you have access to extensive enterstarts sdk that allows you query and manipulate platform objects and services.
Api Gateways have also access to "Package System", which is an extensible nodejs packaging system allowing reuse of nodejs modules among diferent applications.
Sneak Peek
Here's a demo api, that just retrieves and caches fortnite store items:
Package System
The Package System is comprised of modules that contains nothing more than exported nodejs funcionality. In this example, we are showing the aerospike-client service present in the core-sdk package.
Package services can be accessed inside applications by using the include function rather than require. The standard require function is limited to native nodejs packages.
Benefits
Enterstarts API Gateway (EAG) has many benefits for developers and IT companies:
- High performance (single digit millisecond)
- Integration with AWS Lambda and AWS API Gateway
- Reduce development time
- Quick dev cycle - (Edit->Save->Reload)
- Hot Reloads (no more Ctrl-C)
- High reusability ration (with packages)
- Build for small and big teams
- No more wasting time with npm installs
- Batteries included for cloud (aws), messaging (rabbit & kafka),
- Automatic scaling
- 100% control
AWS SDK
At Enterstarts we operate large portions of our global platform on Amazon Web Services. For this reason we dedicate great efforths to simplify on-boarding on core aws services and developer productivity, security and criativity.
Amazon Dynamo Demo
Here's an example of how to query Amazon DynamoDB from API-Gateway
Aerospike DB
Aerospike is the key value store of choice on the enterstarts platform. Heres a demo of usage
Authentication
Using this bit of code you can make sure the user is authenticated on the platform.
const sdk=include("core-sdk/api-service");
function FromToken (token) {
var api=new sdk.APIService("auth", token);
return api.get("verify-token");
}
function Handler(context, req, res) {
var token = req.headers['authorization'];
FromToken(token)
.then(function (authUser){ // {id, name, ... }
res.status(200)
}, reject);
function reject(error) {
res.status(400)
.send(error);
}
}
exports.Handler=Handler;
Query Data
This code allows you to get an object by id and send it as a response without requiring authentication, provided you use your own api-keys to make the request.
The code
const sdk=include("core-sdk/api-service");
const fetch=require("node-fetch");
function Handler(context, req, res) {
const tokenAuth={
// token
// apiKey
// apiSecret
// isAPIKey: true|false
};
var api = new sdk.APIService("zstorage", tokenAuth);
const recordId='...';
api.get("record/"+recordId)
.then(function (Resp) {
res.send(Resp);
}, function (Error){
res.status(400)
.send(Error);
});
}
exports.Handler=Handler;