URLSearchParams allows you to compose easy-to-understand API calls
1 minute read
Use UrlSearchParams to ensure your code is readable
With JavaScript’s UrlSearchParams function, you can compose API calls that would be recognisable as a set of Postman key/value parameters. For example:
In Postman
In JavaScript
Something similar in an SDK (Google Places Library)
Often, a system’s SDK/API library is not as intuitive or broadly understood as a standard like Open API. With SDKs, you rely a little more on the developer documentation being easy to follow and consistently constructed.
SDK versus REST API
The advantages of using a system’s provided SDK instead of a REST API (whether that be Open API, a Postman collection, or some other standard) are that it will:
Have no deployment issues (such as CORS)
Be faster
Be more conservative with its use of resources
Have more commands
Be free of any constraints imposed by a standard API specification.
However, if there is no SDK for your preferred development platform, a REST API may be your only option. For REST APIs, there’s also a significant advantage in the degree of clarity that comes from a standardised approach.
The two APIs combined: “Popular places for food in your area (from Foursquare, on a Google map)”