A Thin Server with an Attitude
Koast consists of two parts:
A server side npm module "koast", which you can install with npm install koast. This module allows you to create a server. In a typical case, you would write a few lines of code to instantiate and start a server, defining most of the functionality through configuration files, a schema file, and a module implementing the API.
A client-side bower package "koast-angular", which you can install with bower install koast-angular. This provides an AngularJS module that helps your frontend app talk to the backend server. You don't have to use it: if you prefer you can just talk to the server directly. However, the frontend module might save you a bit of time.
To get koast up and running quickly, just run
koast init, it will then prompt you to select some basic configuration for your app.
_ _| | _____ __ _ ___| |_| |/ / _ \ / _` / __| __|| < (_) | (_| \__ \ |_|_|\_\___/ \__,_|___/\__| Is now initializing your app <3? Package name: koast-app? Description: A koast app? Include frontend: Yes? Include default gulpfile: Yes
Which will create this file structure:
├── bower_components -- only if 'include front end'├── client -- only if 'include front end'├── config│ ├── app.json -- global configuration│ └── dev| └── dev.json├── server| ├── app.js -- server application| └── api.js -- example api└── gulpfile.js -- only if 'include default gulpfile'
Koast has a high level of customization when it comes to loading configuration files. The init process will create a default
config/app.json that your app will use to bootstrap itself.
Note, for a quick-start (or for testing) you can explicitly set your configuration within your
/* app.js */var koast = require'koast';var appSettings ='app':'indexHtml': 'path:../client/index.html''portNumber': 8081'routes':'route': '/api/v1''type': 'module''module': 'server/lib/api''databases':'host': '127.0.0.1''port': '27017''db': 'erg''schemas': './server/schemas.js''handle': '_';koastconfigureappConfiguration: appSettings;koastserve;
To quickly create api end-points with a MongoDB backend, an application can use the koast mongo-mapper. To use mongo-mapper, simply create a schema file like below:
/* schemas .js */exportsschemas =// Represents a task.name: 'tasks'properties:taskId: Numberowner: Stringdescription: String;
and define a koast module to setup your routes:
/* lib/api.js *//* global require */'use strict';var koast = require'koast';var koastRouter = koastkoastRouter;var connection = koastdbgetConnectionNow;var mapper = koastmongoMappermakeMapperconnection;var defaults =return true;;mapperoptionsuseEnvelope = false;var routes =method: 'get'route: 'tasks'handler: mappergetmodel: 'tasks'method: 'get' 'put' 'post' 'delete'route: 'tasks/:_id'handler: mapperautomodel: 'tasks';moduleexports = exports =koastModule:defaults: defaultsrouter: koastRouterroutes defaults;
When running this application with node server/app.js, you will have a quick CRUD application setup for your tasks schema.
More in depth documentation is available at rangle.github.io/koast-documentation. This documentation goes into more details about how to configure koast, the features supported and the other modules that are available.