Introduction to Punk API

Punk API is a public API service that serves beer information worldwide. It is a useful resource for developers who are working on beer-related apps, websites, and other projects.

In this blog, we will be discussing the different endpoints that Punk API provides and the examples of calling them using JavaScript.

API Endpoints

There are several endpoints that Punk API provides, including:

  • /beers - retrieve a list of all the beers
  • /beers/{id} - retrieve a single beer by its id
  • /beers/random - retrieve a random beer
  • /beers?abv_gt={number} - retrieve a list of beers that have an ABV greater than the specified number
  • /beers?ibu_gt={number} - retrieve a list of beers that have an IBU greater than the specified number
  • /beers?ebc_gt={number} - retrieve a list of beers that have an EBC greater than the specified number
  • /beers?food={food} - retrieve a list of beers that go well with the specified food

Examples

Here are some example code snippets that show how to call Punk API endpoints using JavaScript:

Retrieve a list of all the beers

fetch('https://api.punkapi.com/v2/beers')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Retrieve a single beer by its id

fetch('https://api.punkapi.com/v2/beers/1')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Retrieve a random beer

fetch('https://api.punkapi.com/v2/beers/random')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Retrieve a list of beers that have an ABV greater than the specified number

fetch('https://api.punkapi.com/v2/beers?abv_gt=7')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Retrieve a list of beers that have an IBU greater than the specified number

fetch('https://api.punkapi.com/v2/beers?ibu_gt=50')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Retrieve a list of beers that have an EBC greater than the specified number

fetch('https://api.punkapi.com/v2/beers?ebc_gt=20')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Retrieve a list of beers that go well with the specified food

fetch('https://api.punkapi.com/v2/beers?food=steak')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))

Conclusion

Punk API is a useful resource for beer-related projects, and its endpoints provide a wide range of information about beers. We hope that these examples will help you to get started with using Punk API using JavaScript.

Related APIs in Food & Drink