Small server POC for a REST API to store link to be read.
This was made to compare express
and hapi
node.js frameworks.
Enable to store link, to which you can attach tag so that you miss any link.
The api is available on Heroku
Pending Link is a REST API about one specific resource, Links
Links consist in an url
, a comment
, a set of tags
, a timestamp
, and a status archived
, and an id
. They are available on the server at the endpoint /api/links
with the standard POST
/GET
, and GET
,PUT
,DELETE
on the subresources
Server also have another endpoint /api/hello
to ping if the server is online
For more details, See Raml api specification here :)
Configuration is using nconf so you can tweak it from the command line or with environment variable.
The main configuration points are the listening port pl:port
, the base uri pl:base_uri
and the path of the nedb
database db:path
.
To be specified in details
With pending link, you can either use nedb as in memory database, or a dedicated collection on a mongo database.
The switch is done with the db:in_memory
option.
The /heroku/ application available is running along with a /MongoLab/ cloud instance.
To be specified in details
The best example of a config is the default one:
{
"pl": {
"application_name": "pending-link",
"listening_address": "0.0.0.0",
"port": 12121,
"base_uri": "/api/v1"
},
"log": {
"level": "debug",
"stream": "process.stdout",
"path": ""
},
"db":{
"in_memory": true,
"config": { "path": "./link.nedb" }
}
}
Documentation from raml spec can be generated with raml2html
available on npm
,
regenerate them using raml2html api-raml.yaml > public/api.html
Can be invoked with npm run generate-doc
, or with npm run build
that will also
update the homepage from the jade template.
As you may expect, tests are in test
, and code in src
folder.
Hapi and Express specific files are respectively in the hapi
and express
folder.
The app.js
at the root of the project decide which one to load based on command line argument.
The common object links and it's dao are in the links
subfolder, and the config
in the folder with the same name.
Logging is being done using Bunyan So if you run the process, you better pipe it to bunyan program.