× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Diagnosing web service integration issues

Jessamyn Smith
Jun 12, 2015
<p>Let’s say you have a mobile app that needs to make an API call, and an error is occurring. Diagnosing issues inside a mobile app can be slow and difficult. It’s far easier to isolate components of the system and verify them one by one. A good first step is to verify that your API call works correctly. You can do this quite easily using curl. An example curl call to a JSON API, for GET:</p> <pre><code class="language-bash">curl -v -k -X GET --header "Content-Type: application/json" "https://underquoted.herokuapp.com/api/v2/quotations/?format=json&amp;text__icontains=and&amp;text__icontains=enemies" | python -m json.tool</code></pre> <p>and for POST:</p> <pre><code class="language-bash">curl -v -k -X POST --header "Content-Type: application/json" --data '{"text": "Women have been trained to speak softly and carry a lipstick. Those days are over...", "author": "/api/v2/authors/1/"}' "https://underquoted.herokuapp.com/api/v2/quotations/?username=jessamyn&amp;api_key=someverysecretkey"</code></pre> <p>You can debug your mobile application to see what headers, url parameters, and data you are passing, and then write a curl request that mimics the mobile request.</p> <p>Curl gives you quite a bit of information, especially with the -v option, and allows you to quickly modify your request until it works. Once you have a working request, you can try making your mobile app mimic that exactly. If you still receive errors, there is a good chance your mobile app isn't configured to allow external requests.</p> <p>Curl is also very useful for testing APIs that you have created. I recommend running your application locally first, so that you can see all the debug info, and making curl requests against localhost. Once your request works locally, you can deploy that version of the code to your hosting provider. Then, make the same curl request but with the server url rather than localhost, and ensure that it works as expected. Most hosting providers will give you some access to application logs, but it may not be as comprehensive as what you can see when running locally.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus