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));
@LyudmilC-dacc-939
Copy link

Hello, I wrote an email to sapphire regarding a small inconvenience I'm having, is there any chance you CAN write such form for Java(I need it for a personal project that is going to make real requests/calls to your APIs)? It's quite a primitive Java code that I have to use public API and wanted to use this one.

@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