Introducing JSON Feed Server – An open source project that uses Nodejs, Express, Mongoose and MongoDB

Post to Twitter

Today I’m announcing a new open source project I’ve been working on for a short while. JSON Feed Server is a Nodejs based JSON feed server that you can use to HTTP POST JSON data into and use HTTP GET to retrieve the information back out. If you’ve worked with an ATOMPub server you can think of this as a simpler in scope (and therefor complexity) way to store and get JSON data via a feed. ATOM however has an actual RFC, JSON Feed Server doesn’t but is simple enough anyone can understand it.


The first question many will ask is: Why another feed server? My first answer would be that although ATOM is very common and widely used there are certain specific projects that deal only with JSON data so why not have a pure feed server for just JSON based products? Yes, you can convert JSON and stuff it into ATOM XML but that then means you will do double parsing to get it back out. My second answer would be that as the web evolves so do the needs of people, teams, projects. Where ATOM or RSS naturally was a good fit at one point it might not be the best fit for every project. Clearly though there are differing pros and cons of why you would choose to use ATOM/RSS or JSON – they both have their merits. Decide what is the best and go from there. I’ve recently blogged about another open source project called Atom Hopper that works very well for ATOM based projects. So JSON Feed Server should be seen as an alternative to ATOM, not as a competitor. Pick what works for your needs and go with it.

Even though JSON Feed Server is being announced it’s still in need of plenty of work and should not be seen as anywhere near production quality yet – it’s experimental at best. As of the date of this article JSON Feed Server still needs unit tests (it currently only has one test), better error handling, etc. It’s a work in progress and your welcome to send pull requests and submit issues. I’ve built this project using Nodejs of which I’m still learning all the nitty gritty details of so I’m hoping people with valuable input will help out with the codebase. I also decided to use MongoDB as the primary backing store at this time and my initial benchmarks have shown that Nodejs and MongoDB run very fast and well together. There is also potential to add in support for Socket.IO to have realtime feed updates.

Why would you use JSON Feed Server (JFS)?

There are several reasons really and probably many more I haven’t even thought of at this time. The primary reason in my mind is you have two systems that need to talk to each other. Perhaps you have a system that generates events and you have some front ends, dashboards, or something else that listens to these events. Assuming the events are generated in JSON format then it’s easy to publish these events to the JSON Feed Server. Simply post the JSON data in the body and do an HTTP POST to the JSON Feed Server. You can POST to any route on the server and that will be the route that will then be used to retrieve the event(s).

Example:

Lets say I need to post some JSON data for an event that a system generated. The JSON might look like this:

{
    "content": "Server 184 has reported it is ready",
    "event": {
        "type": "System Alert"
    },
    "updated": "2012-02-19T07:40:00Z",
    "title": "Incoming Message"
}

I do an HTTP POST (Content-Type: Application/JSON) to the JSON Feed Server: http://some-address.com/my/generated/events/

In this case you could then do an HTTP GET to the above URL and get the JSON returned, in fact you would get a feed of JSON entries back assuming there were more than one JSON entries in the database.

You can easily create your own routes on the fly, so using this one: http://some-address.com/my/generated/events/ is fine, but lets say I also want to have one for an event of when a major news event happens or something, then I could use something like this: http://some-address.com/breaking-news/ or http://some-address.com/news/ etc.

JSON Feed Server will accept any valid JSON data.

You can get back to your single JSON entries or multiple entries (the default coming back is 25) using HTTP GET and the self referencing links. You can also page through entries as well as my future plans to use tags to categorize your JSON entries making them easier to locate via a query.

A returned feed might look something like this:

{
  "4f419e771c69848a02000005": {
    "body": {
            "content": "Server 184 has reported it is rebooting", 
            "event": {
                "type": "System Alert"
            }, 
            "updated": "2012-02-19T07:40:00Z", 
            "title": "Incoming Message"
        }, 
        "selfHref": "http://localhost:8080/feed/?id=4f419e771c69848a02000005", 
        "entryDate": "2012-02-20T01:14:31.763Z"
    }, 
    "4f419aba1c1d6b7c02000005": {
        "body": {
            "content": "Server 80 has reported it is out of memory", 
            "event": {
                "type": "System Alert"
            }, 
            "updated": "2012-02-19T05:16:00Z", 
            "title": "Incoming Message"
        }, 
        "selfHref": "http://localhost:8080/feed/?id=4f419aba1c1d6b7c02000005", 
        "entryDate": "2012-02-20T00:58:34.738Z"
    }, 
    "4f41930e70c8fc1102000001": {
        "body": {
            "content": "Server 1042 has reported it is operational", 
            "event": {
                "type": "System Alert"
            }, 
            "updated": "2012-02-19T23:20:02Z", 
            "title": "Incoming Message"
        }, 
        "selfHref": "http://localhost:8080/feed/?id=4f41930e70c8fc1102000001", 
        "entryDate": "2012-02-20T00:25:50.939Z"
    }
}

Where can I get JSON Feed Server?

The GitHub repo is here: https://github.com/chadlung/jsonfeedserver

Primarily I’ve run JSON Feed Server on Ubuntu 11.04 and Mac OS X Lion. I have not tested it on Windows at all.

JSON Feed Server is licensed under the Apache 2 license.

Check out the readme to see how to use it!

Post to Twitter

This entry was posted in Atom Hopper, JSON Feed Server, MongoDB, Node.js. Bookmark the permalink.