Codebyjeff Laravel Quick Tip

Hello Laravel Friends!

An ever increasing part of our job these days is creating back-end apis (something I'm actually starting to specialize in these days, it is such a requested item). There are a lot of great tools being developed to help with building and testing these, but Postman ( is one of my most critical. Postman lets you create the urls you need to imitate an iOS app or Curl calls - actually, it has so many helpful features you'd do best to just go skim the docs!

Two tricks I wanted to show you today that are *enormous* time-savers. Going to break with my habit of boring, text-on-white posts today because I think images will be much more helpful in explaining.

The first is using environments. Go to the little cog in the upper-right corner of the tool and you'll see "Manage Environments":

Add a new environment with your site's local url and a blank token variable we'll use in the second part of this newsletter:

Now in the dropdown select "MySite" (or whatever you named it) and create a new url with a variable:

The {{url}} will be filled in with your variable. Why is this cool? You can export your Postman collection and share it with everyone else on the team, and they can simply change that variable to their own local url or staging url without having to change every single endpoint! No more arguing over whether to use ".dev" or ".local" or whatever - everyone is free to do as they prefer, and a quick swap to check staging and production.

The second part of this is even better! These days using JWT Tokens and stateless APIs is the norm, which means you have to go get a token and then pass it back with every request in the headers. That's a pain! However, we can take advantage of Postman's test scripting to handle this for us.

(Note: this is a fairly standard setup, but your own may need some tweaking.)

First, we have a POST endpoint to {{url}}/login that returns the token:

Assuming a response of {..., message.token} go to the "tests" tab and add this script:

This is just javascript, and should be pretty clear what is happening. Now, go to any of your endpoints and set up your Headers:

Now when you start your work session, just go log in and all of your endpoints will have the token populated for you at once. That's a bit of a time saver, I think.

Hope that helps!

Thanks for reading! If you found this useful, help me spread the word  share on Twitter

Read it Monday, use it by Friday!


Copyright © 2017 Jeff Madsen Designs, All rights reserved.

Want to change how you receive these emails?
You can update your preferences or unsubscribe from this list

Email Marketing Powered by Mailchimp