Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,671
6,212
I'm writing an app for my server which has a RESTful API. Thus far, to quickly test features as I add them, I just use curl on the terminal to see if a POST or GET request is working properly. When they work properly, I get an easy to read JSON response. When it doesn't work, I get 2000 lines of HTML produced by Django. It's fairly tedious to have to copy and paste this response into a text file, save it, then open it in a web browser to view what the details of the error are.

There has to be an easier way of doing this. I could probably write a small command line utility which would run curl for me, grep for </html> and respond with the JSON if it's not found, or save the results into a tmp file and open it in a browser if it does find that... in fact, that's probably easier done then said.

Still looking to hear what solutions other people have.
 
I'm writing an app for my server which has a RESTful API. Thus far, to quickly test features as I add them, I just use curl on the terminal to see if a POST or GET request is working properly. When they work properly, I get an easy to read JSON response. When it doesn't work, I get 2000 lines of HTML produced by Django. It's fairly tedious to have to copy and paste this response into a text file, save it, then open it in a web browser to view what the details of the error are.

There has to be an easier way of doing this. I could probably write a small command line utility which would run curl for me, grep for </html> and respond with the JSON if it's not found, or save the results into a tmp file and open it in a browser if it does find that... in fact, that's probably easier done then said.

Still looking to hear what solutions other people have.

I'd probably do that. Sounds like a few lines of shell script to me.

You can tell grep to not print matches, only set its exit status according to found/not found. Then the && or || conditionals can easily link an 'open savedFileHere.html' as a consequent of failing to match "</html>". And yeah, it's simpler to sketch that as shell commands than to describe it, e.g.:
Code:
curl "$@" | tee savedResponse.html
grep -iq "</html>" || open savedResponse.html
That's the gist of it, but I'd run it a few times and play around with it.

I'd just put it in a shell script and add it to my ~/bin dir (which I've added to my PATH). If you don't want a ~/bin, there's probably a /usr/local/bin you can put it in (which you might need to mkdir first).
 
We made a javascript program that just hits all the possible API requests and says if they passed or failed.
 
We made a javascript program that just hits all the possible API requests and says if they passed or failed.

Yeah, we have a set of iOS unit tests that test the iOS API Framework, so if any of those tests fail we know either the iOS API is wrong, or more likely, the web API is wrong (because the iOS code is really simple, just taking the arguments and packing them into proper HTTP requests or getting responses and decoding them to objects).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.