A simple nodeJS app to wrap the United States Postal Service's CityStateLookup XML API and return a JSON object.
-
You can almost instantly get a USPS api key by filling out the registration form at https://www.usps.com/business/web-tools-apis/
-
Clone this repository and create a
.envfile in the root of the project that looks like this
USPS_API_KEY=YOURUSERNAMEHERE
-
Run
npm installthennpm start -
Profit
http://production.shippingapis.com/ShippingAPI.dll?
API=APINAME&XML=<CityStateLookupRequest USERID="APIKEY">
<ZipCode ID='0'>
<Zip5>74801</Zip5>
</ZipCode>
</CityStateLookupRequest>
<?xml version="1.0" encoding="UTF-8"?>
<CityStateLookupResponse>
<ZipCode ID="0">
<Zip5>74801</Zip5>
<City>SHAWNEE</City>
<State>OK</State>
</ZipCode>
</CityStateLookupResponse>
http://localhost:8080/?zip=74801
{
"zipCode": "74801",
"city": "SHAWNEE",
"state": "OK"
}