Autosuggestion and validating Belgium addresses

It was one of those days where I had some time and was building yet another open sourced project. I wanted to add an address input field to my project, but I didn't want to use the Google Maps API. I wanted to find a free API service that would provide me with a way to validate and get suggestions for my address input field. I eventually found an API service that did just that.

bpost-logo-git-validate-autosuggest

After conducting research on address validation, I found that BPOST, a well-known post delivery company, offers this service. BPOST was previously owned by the government and was called De Post. For more information on BPOST, please see the following link: https://nl.wikipedia.org/wiki/Bpost.

I was looking for information about the bpost REST API in the developers docs, but there was no written documentation about the address validation service. I found a SOAP API, but even that didn't have any information about the address validation service. Then I looked up their services and found the gem "Address suggestion and validation for the public". Unfortunatly, they claimed to have a limitation of 20 requests per day.

I was curious about how they build the backend, so I looked into the Netwerk tab and tested the REST API endpoints for both validation and autosuggestion. I found that there was no limit on the autosuggestion, and neither on the validation (at least not 20 reqs/day).

To be honest, I wouldn't be surprised if they didn't have any limits at all. Based on my investigation, they didn't set up any headers for api request limits (as of date 17/10/2020).

Making a wrapper around their undocumented public service

After finding this possible solution, I thought it would be beneficial to make the wrapper around these REST API endpoints public so that everyone can use it, rather than spending hours on research and development like I did. However, this had a little surprise for me that I was able to handle.

So I started another open source project called address-validation-and-autosuggestions.

This package uses axios to make both the get (autosuggestion) and post (validation) requests. I thought that adding TypeScript would make it more interesting. If we lookup bpost's github, they do have an angular embed/component shared to the public. However, they don't use any typing, so I must figure out the typings and interfaces for the wrapper package myself.

The little suprise

I was testing their endpoints using postman and didn't come across any issues. However, when I started writing the wrapper using axios and tested the package, I came across an error; Request Header Fields Too Large.

I wasn't really surprised since I didn't catch this when I was using postman since postman has no header limitation build-in. When investigating Bpost's service, I saw their strange long headers and realized that this was the cause of the error.

The solution for the little suprise

Fortunately, the solution was not too complicated. It was something related to a default set http headers size by node itself. For security reasons, the default of 80KB went all down to 8KB and, as you might guess, this size was not enough for BPOST's api. More about the reason behind can be read here and here.

The solution, as described in the first article linked above, was adding the flag --max-http-header-size=30000 when starting the node server.

Summary And Conclusions

This article discussed a research project conducted to find a free API service that would provide address validation and suggestions. I did eventually found a service offered by BPOST, but found that there was no written documentation about the address validation service. I conducted an investigation and found that there was no limit on the number of requests that could be made. Then I decided to make a wrapper around the REST API endpoints publicly avaible so that everyone could use it. However, I ran into an issue with request headers that was eventually resolved.

If you know what to search for and where to look, you will always find a solution. Thank you for reading my account of finding a solution to a minor problem. If you have any suggestions or questions, related or not related to the article, you can contact me directly using the contact information on the About page.