During this week I created a demo API using Sails. It is not something very special to be done during a week, but I didn’t really work too much on it. During the past weeks I used to work 3 hours/day on the projects, but this week wasn’t the best. One or two days I couldn’t work at all on this. Anyway, it gives the basic idea of building a simple API in Sails. It handles five routes, all sharing the base
|GET||api/v1/ship/||Get the list of all ships stored|
|GET||api/v1/ship/:id||Get the data for a single ship with the ID of
|POST||api/v1/ship/||Insert a ship in the database|
|PUT||api/v1/ship/:id||Update data for a ship with the given ID of
|DELETE||api/v1/ship/:id||Delete the ship with ID of
The data is stored in a Mongo database. Sails comes with a simple-to-use ORM/ODM called Waterline, which makes it very simple to use any kind of database management system, both SQL and NoSQL. If you need to change the DB management system, all you have to do is install the proper database driver, change the configurations file, and that’s it! The interface that Waterline gives to you is the same and DB-independent, so the rest of the code remains the same.
Unfortunately, I didn’t add any kind of validation or authentication/authorization mechanism, which is not cool. Next week, I intend to add such things, both a validation mechanism (so the data posted is the right one) and an authentication/authorization mechanism (so not all users can delete and/or update data). Maybe in a later time, I’ll use the same application for playing with some Android development, probably using Reactive Extensions for Java.
This is for the 4th week. If you want to check the application, you can find it on GitHub with other information on how to run the application. I included the exported data from MongoDB, so you can use the same data if you want. Also I added some shell scripts that I used to test