Skip to content

Instantly share code, notes, and snippets.

@mekarpeles
Created May 22, 2024 15:58
Show Gist options
  • Save mekarpeles/0d308bfd8e75858d2266b8aa983cac07 to your computer and use it in GitHub Desktop.
Save mekarpeles/0d308bfd8e75858d2266b8aa983cac07 to your computer and use it in GitHub Desktop.
js example of adding app identification headers to openlibrary.org API calls
const url = "https://openlibrary.org/search.json?q=test";
const headers = new Headers({
"User-Agent": "MyAppName/1.0 (myemail@example.com)"
});
const options = {
method: 'GET',
headers: headers
};
fetch(url, options)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
@mekarpeles
Copy link
Author

It's a network request so you should be able to adapt this to any language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment