Case Study

TUTORIAL: Verify Addresses with the Streetlayer API

A street address is one type of data you don’t want to get wrong. Whether you’re building an app for mailing, shipping or legal purposes, getting an address right is integral to having your product, you know, delivered. Having an invalid (or incorrectly typed) address could cause delays and annoyance for your app’s users, and cost you a lot of money.

Validating data is a core best practice of software development. Unlike other types of data, however, addresses are notoriously hard to validate for the following reasons:

  • Lack of universal structure: Do you type 345 Abbey Rd. or Abbey Rd. 234? Depending on where your users are from, the answer varies.
  • Variety of parameters: The many different inputs (apartment / suite numbers, road / street / avenue etc. ) makes validation even more challenging.
  • International variance: When you have customers from all around the world, handling international address verification makes this already difficult task even harder. Just as an example, not all countries have states / regions within them, while in other countries it is not uncommon for the same city to appear twice in two regions.

It almost makes you want to give up on verifying addresses all together.

Source: xkcd

Luckily, we have the StreetLayer API!

The Streetlayer API is an easy-to-integrate solution for address verification. It can verify addresses nationally and internationally. From a basic check we’ve performed on a few hundred addresses with https://openaddresses.io, it seems to be highly accurate. Beyond the standard address verification, StreetLayer also offers geocoding – a way to turn your addresses into latitude longitude coordinates. This geocoding feature could be highly useful if you want to present an address on a map.

One of the aspects that we like best about Streetlayer is its ability to treat addresses in a structured way. The API breaks addresses down into their logical components (country code, street, house number, state etc…). If you’re going to store address data in your database, this could be a great way to break down the data rather than store an unparsed string. Storing it that way will also allow you to query by street / country / region down the road (pun not intended).

Step 0: Get a Streetlayer API key

To start using the StreetLayer API, head over to https://streetlayer.com and click ‘Sign Up Free’ in the top right corner.

Streetlayer Pricing

StreetLayer has a free tier with up to 50 requests / month. This tier should be plenty for this tutorial and for development, though you may want to scale up to the Basic ($9.99 / month) or Pro ($49.99 / month) as your app moves into production.

Once you’ve finished the signup process, you’ll be taken to the dashboard and presented with the API key. Keep that as it is required to identify you in every API call you make.

In the dashboard, you can also view your API usage (in the left menu). It’ll show you how much of your plan you’ve used up.

Step 1: Use RapidAPI to Make an API Request

Now that you’re all set up with Streetlayer,  head over to StreetLayer on RapidAPI to start making requests. RapidAPI will let you test a Streetlayer API call in your browser, then you’ll be able to export the code snippet in your preferred language.
We’ll start out by using the validateAddress function. Enter your API key and and address and click test.


Your response should look like this:

[  
   {  
      "success":true,
      "validation_status":"valid",
      "address_components":{  
         "country_code_alpha2":"US",
         "country_code_alpha3":"USA",
         "country":"United States",
         "county":"San Francisco County",
         "locality":"San Francisco",
         "postal_code":"94105",
         "region":"California",
         "region_code":"CA",
         "street":"Beale St.",
         "housenumber":"388",
         "neighbourhood":"Rincon Hill"
      },
      "validation_result":{  
         "locality":true,
         "county":null,
         "region":null,
         "postal_code":null,
         "street":true,
         "housenumber":true
      },
      "formatted_address":[  
         "388 Beale St.",
         "San Francisco, CA 94105",
         "United States"
      ],
      "coordinates":{  
         "latitude":37.787676,
         "longitude":-122.391777
      }
   }
]

In the response you can see that the validation_status parameter is set to valid, and thus the address is valid. You can also see the three line formatted_address and the address components.

You can copy the code into your app in order to verify addresses. Since it’s also considered best practice to verify all data received in the backend, you could easily verify the address there as well.

 

Bonus Step! Add Address Auto-Completion

StreetLayer can also be used in the front end to auto-complete addresses.

As we all know, entering addresses can oftentimes be tedious. Having to type your zip code, street address, state and country every time you use an online service is a true annoyance. No wonder address entry is one of the biggest drop-off points in online forms!

StreetLayer has another function set to change this – autocompleteAddress. You can pass this function a fragment of an address and get suggestions for possible addresses. Using a library like jQuery UI, you can show those suggestions to the user in a dropdown. Much like the suggestion given in Google search, this functionality will save your users the effort of address entry.

Here is a small jsFiddle using StreetLayer’s autocomplete functionality with jQuery UI. Every time a user types in a fragment of an address, jQuery will call the autocomplete function (see below). The function will make a request to RapidAPI with the text and pass back an array of options, which jQuery will then show to the user.

You can checkout the complete jsFiddle here.

Conclusion

Overall, the Streetlayer API a great way to make sure your users are entering valid addresses frustration-free. Better yet, unlike services like Google Maps, this solution is 100% white label, not requiring you to put a 3rd party logo on your website. Test an API call for yourself and let us know what you think!

 

4.7/5 - (43 votes)
Iddo Gino

Iddo Gino is the Founder and CEO of RapidAPI. Part of Forbes 30 Under 30 list, he's a 2017 Thiel Fellow. Previously, he was a Co-organizer of Hacking Gen Y. Iddo has been programming since he was a kid and continues to contribute to open-source projects. Originally from Haifa, Israel, Iddo is based in San Francisco, CA.

View Comments

Share
Published by

Recent Posts

Power Up Your Enterprise Hub: New March Release Boosts Admin Capabilities and Streamlines Integrations

We're thrilled to announce the latest update to the Rapid Enterprise API Hub (version 2024.3)!…

2 weeks ago

Unveiling User Intent: How Search Term Insights Can Empower Your Enterprise API Hub

Are you curious about what your API consumers are searching for? Is your Hub effectively…

3 weeks ago

Rapid Enterprise API Hub Levels Up Custom Branding, Monetization, and Management in February Release

The RapidAPI team is excited to announce the February 2024 update (version 2024.2) for the…

1 month ago

Supercharge Your Enterprise Hub with January’s Release: Search Insights, Login Flexibility, and More!

This January's release brings exciting features and improvements designed to empower you and your developers.…

3 months ago

Enhanced Functionality and Improved User Experience with the Rapid API Enterprise Hub November 2023 Release

Rapid API is committed to providing its users with the best possible experience, and the…

5 months ago

The Power of Supporting Multiple API Gateways in an API Marketplace Platform

In today's fast-paced digital world, APIs (Application Programming Interfaces) have become the backbone of modern…

6 months ago