BETA
My accountGet started
Nov 292016
Total.js Platform

Quick API server for testing

When you need an API server for testing there's Total.js framework to get you up and running in minutes.

Quick API server for testing

When you need an API server for testing there's Total.js framework to get you up and running in minutes. If You want to know how then keep reading.

  • first of all let's create a folder and install Total.js
  • now let's create index.js which will be the only file we need:
  • open the file in your favorite Sublime Text editor :)

Server

First thing we do is setup a server using framework.http:

The above code can be used as a static file server. If You create a public folder then whatever you place in there will be accessible. e.g. ./public/favicon.ico => localhost:8000/favicon.ico.

Schema

Next we setup a schema and some properties using SchemaBuilder.

Routes

Now it's time to create some routes using F.route. In each route we use *Product flag which tells the framework we want to use the schema methods in a controller.

Controllers

Since we've specified the *Product flag we can use schema methods such as $get, $query, $save, etc..

Logging requests

Let's add logging for each request so we know what's going on:

Find the gist here index.js.

Extra

If you want it to work really quickly you can use recently added functionality NOSQL inmemory. Add it just bellow require('total.js').http('release');.

This will keep all documents from products collection in memory for quicker access.