Using Postman to test RESTful APIs

in MEAN, Tools
March 8th, 2016

There’s a sharp divide in MEAN projects between the back end and the front end. Most use cases involve manipulating model data in some way via either a controller or view-controller, which in MEAN is implemented in Angular. The first work to be done, though, is on the back end, defining and implementing the models and the APIs that sit on top of them.

The typical work flow looks something like:

Screen Shot 2016-03-08 at 3.59.43 PM


That split is possible because the front end and back end are decoupled; one person can work on the front end and another on the back end once the API has been agreed upon.

There’s on tiny problem. How can we test the back end if the front end isn’t finished? Let’s say you will at some point have a very nice Angular form that lets you create a complex object, and display the results, but it isn’t finished, or test requires generating data for multiple views that aren’t complete. In these cases we turn to a variety of tools to exercise the back-end API; one of my favorites is Postman, available at

Postman is essentially a GUI on top of cUrl, a command-line tool that allows us to interact with HTTP services. cUrl isn’t too hard to use, but for complex queries it can become a real pain to type everything in the correct order and syntax. Postman takes care of the complexity with a forms-based interface to build, send, and display the results of just about every method you can think of.

Here’s Postman’s main interface:

Screen Shot 2016-03-08 at 4.08.52 PM

To use it, simply enter the URL of the API you want to test, and enter the appropriate parameters. In the screen shot above I’m doing a GET, passing one parameter, and receiving a JSON object as a result. You can save and edit queries, place queries into tabs, run queries in series, and select an authorization model if you’re using one. Also of interest is the ‘Generate Code’ link which will create code in several languages (Java, Javascript, Node, PHP, Ruby, Python, etc) that you either use directly in your code or include in your test suite.

While Postman and tools like it simplify back-end API development, it’s also useful in creating JSON stubs for front-end Angular devs to use for testing until the back end models are fully functional. You can also use it to explore third-party APIs that you might be using…just click Generate Code in the language of your choice to spit out a function to consume the API.

Postman and tools like it solve the chicken-and-egg problem of decoupled development models. It’s free, and I think it belongs in every engineer’s toolbox.


Post Your Comment