I am making an Android and iOS app that is going to interact with a server using an API that returns appropriate JSON responses. Someone else on my team is doing the server side work. I don't want to bother/wait for her to finish the server implementation.
Is there a web site out there that will help me create a test API so that whenever I call it, it will return a predefined JSON response?
Example: if the web site is called api.com
and so if I create an account and call GET api.com/my_account/get_key
it returns {"key": "fgjllpoiunvxaqw"}
. I will hardcode the response on the website of course.
If you are just reading data from the server (e.g. making only /GET requests) you can put some .json files on server and just read them from your app.
For example, for get_key, you could call GET yourwebsite.com/get_key.json
and parse the data. This way you can simulate how your app works with network delays, which is very useful to start adding loaders and error handling UI.
If you need to POST, I usually have a PHP script to write to a file on the server, to check later what it's being posted:
<?php
file_put_contents('testPostUserData.txt', file_get_contents('php://input'));
?>
If you require more dynamic interaction (GET and POST data, retrieve some data for a specific user) then you can use some of the services available for free like Backendless, Kinvey, StackMob, or Parse.
Finally, I usually have a preprocessor #define to alternate between fake API and real API
#ifdef FAKE_API
static NSString * path requestBaseURL = @"http://yourwebsite.com";
#else
static NSString * const requestBaseURL = @"http://realwebserver.com";
#endif