I’ve completed the work in implementing the API.
This was surprisingly more complex than expected. I’ve spent a bit of time working with WebApi and I’d also done the work to design the API, but I still ran into a few unexpected issues, some of which required me to change the design of the API.
Finding the IP address
For some reason I’d decided to include logging the IP address of the client machine when people mark a status as liked and when a status is marked as viewed. This proved to be a bit harder than expected. After poking around in the Request object for a while, I resorted to google, which led to this stack overflow question.
When I’d designed the API, I’d had planned GET requests to cover retrieving a single status, searching for statuses and retrieving the status history, all hitting the same URL. I’d slightly naively assumed that this would be handled something like function overloading. I’d also confused this with the simple case where you return all and retrieve a single item by id. In that case, this is handled by routing.
Clearly this doesn’t work, how would the server resolve the HTTP verb to a single function?
As a result I needed to move this to separate the methods using routing. This meant that search became: /status/search as a GET.
Retrieving values passed in
I ran into a few problems trying to retrieve values passed to the server. Should they go in the body? URL? Headers?
In retrospect, probably the best place for the session id would have been as a header. Ideally the authentication for this could be handled as less of a copy and paste implementation. It would be a bit overkill in the current situation though.
Document the UI – I’ve found this tends to make the implementation clearer Implement in bootstrap, MVC4 with SQL Server backend Design JSON API to access app Implement JSON api using WebApi backend
- Swap the SQL Server backend for a No SQL database
- Replace the WebApi backend with an F# implementation
- Replace the WebApi backend with node.js