search_breweries_by_city <- function(city, per_page = 100, page = 1) {
url <- "https://api.openbrewerydb.org/v1/breweries"
query_params <- list(
by_city = city,
per_page = per_page,
page = page
)
response <- GET(url, query = query_params)
content <- content(response, "text", encoding = "UTF-8")
breweries <- fromJSON(content)
return(breweries)
}Open Brewery API
Service Explanation
The Open Brewery DB is a publicly available dataset with public information on breweries, brewpubs, bottleshops, and cideries. On the website, it’s intended purpose it to “maintain an open-source, community-driven dataset and provide a public API for brewery-related data.” as well as a “belief that public information should be freely accessible for the betterment of the community and the happiness of web developers and data analysts.”
Practical Use
There is a few practical reasons why I think someone would want to use this API. The first being that this API allows the user to search for breweries off of a wide range of criteria. If you wanted to see all the breweries in your state, that is possible with this API. You can also search the data for different types of breweries. Whether it be a local brewery, national brewery, or a bar, this API allows for the user to search based off a specific filter.
API Setup
The first step to use this API is to make sure you have the proper packages loaded into R. For this specific API example, you will need the htttr, jsonlite, and dplyr packages.
After loading the appropriate packages into R, we can begin building a practical use for this API. For this specific example, I will use this API to pull a list of breweries by city. The function to do this will look as follows:
Practical Use
The above function is run to pull data on breweries per each city. Say that you had just moved to the city of Cincinnati and you had some time to kill on a Friday night. You want to gather a list of breweries in the city to explore with your boredom. To gather that list based off of the filtered criteria of being located in Cincinnati, the code will look as follows:
cincinnati_breweries <- search_breweries_by_city("Cincinnati")
print(cincinnati_breweries) id
1 950180bd-29c9-46b3-ad0c-e6f09799ec7f
2 ccb3350f-eade-47d0-8fa7-351d20ead048
3 97bb99d6-94da-4f54-8fe7-9d7d7f102556
4 a7928f72-0201-4c7e-bb72-a83016945a2e
5 54028e4d-c6db-43f2-a3f8-75474a41a5d6
6 cee664ba-c129-45ea-a00e-8fad713dcea0
7 7324090e-aaf4-4a30-8370-e8eb664445d0
8 9c92b8c8-750c-4ac9-b9fd-e5b708bb249d
9 a84e6dc3-0e93-455b-8655-819b832b6bc3
10 e16b6c28-c37c-43fe-9234-705513701060
11 bd1649e5-21f8-4e5d-9ab4-e276abb822f6
12 337b4c62-2460-4ae7-b271-d022058469cc
13 b54b16e1-ac3b-4bff-a11f-f7ae9ddc27e0
14 8acae3ab-9840-4619-9f8b-873d262ff38e
15 916efcdf-12c7-4c76-9a22-1312ad526e34
16 c59d0db5-f675-4808-97c4-ab1a38643c58
17 66825536-6e93-4eed-aa6c-eba138076b0e
18 cb19bf9b-71b5-444c-a8a5-00a4fadf1d7b
19 cf1aec2c-18d4-42cc-a4e2-f8407b060607
20 3230d289-2e6c-456c-b9c4-256dc17f44f1
21 4dfeb9cd-7b63-46e6-ac77-76a97d86daeb
22 bc178419-2cae-4a48-8315-21bdc97954d3
23 6e5f19f9-b0cb-424d-ac2a-828ea580bddd
24 ef644d34-4eef-4ab0-8b2f-92ce400e2eb0
25 1068e771-b1ba-47d0-960b-03ef44043ecd
26 251283fc-99a8-447b-b6ba-bf80a8c2ebce
27 bb0ddc58-bfea-4564-8c6a-052d6445d0d4
28 6a7335ee-c49f-4220-89f4-f239d5bf089c
29 efc1fdf0-8856-4d35-b0e9-d6ac2736043a
30 261457bf-6164-49da-b03e-88ce62b1ce17
31 4aa52f48-c03f-45a4-833c-9526e37b2a69
32 c5f18c89-13af-4176-8e2d-9c58ffa7c4b2
33 6d54504b-074c-417a-bb3a-008e26e0b662
34 43ad77a1-454e-4e77-8f8a-8e7c2b542da6
name brewery_type
1 13 Below Brewery micro
2 Bad Tom Smith Brewing micro
3 Big Ash Brewing Company planning
4 Boston Beer Co - DBA Samuel Adams Brewing Co regional
5 Brink Brewing Company micro
6 Christian Moerlein Brewing Co regional
7 Dead Low Brewing planning
8 Fibonacci Brewing Company micro
9 Fifty West Brewing Co micro
10 Fifty West Brewing Co brewpub
11 Listermann Brewing Company micro
12 MadTree Brewing regional
13 MadTree Brewing 2.0 regional
14 March First Brewing brewpub
15 Moerlein Lager House brewpub
16 Mt. Carmel Brewing Co micro
17 Nine Giant Brewing brewpub
18 Northern Row Brewery & Distillery micro
19 Off Track Brewing Company micro
20 Platform Cincinnati micro
21 Queen City Brewery of Cincinnati micro
22 Revel Urban Winery / Revel OTR brewpub
23 Rhinegeist Brewery regional
24 Rock Bottom Brewery - Cincinnati brewpub
25 Streetside Brewery micro
26 Taft's Ale House micro
27 Taft's Brewing Co brewpub
28 Tap and Screw Brewery brewpub
29 The Woodburn Brewery micro
30 Third Eye Brewery planning
31 Three Points Urban Brewery micro
32 Urban Artifact micro
33 West Side Brewing micro
34 Wiedemann Brewing Co, LLC micro
address_1 address_2 address_3 city state_province
1 7391 Forbes Rd NA NA Cincinnati Ohio
2 4720 Eastern Ave NA NA Cincinnati Ohio
3 <NA> NA NA Cincinnati Ohio
4 1625 Central Pkwy NA NA Cincinnati Ohio
5 5905 Hamilton Ave NA NA Cincinnati Ohio
6 1621 Moore St NA NA Cincinnati Ohio
7 <NA> NA NA Cincinnati Ohio
8 1445 Compton Rd NA NA Cincinnati Ohio
9 7605 Wooster Pike NA NA Cincinnati Ohio
10 7668 Wooster Pike NA NA Cincinnati Ohio
11 1621 Dana Ave NA NA Cincinnati Ohio
12 3301 Madison Rd NA NA Cincinnati Ohio
13 5164 Kennedy Ave NA NA Cincinnati Ohio
14 7885 E Kemper Rd NA NA Cincinnati Ohio
15 115 Joe Nuxhall Way NA NA Cincinnati Ohio
16 4362 Mount Carmel Tobasco Rd NA NA Cincinnati Ohio
17 6095 Montgomery Rd NA NA Cincinnati Ohio
18 111 W McMicken Ave NA NA Cincinnati Ohio
19 227 Stark Street NA NA Cincinnati Ohio
20 916 Dalton Ave NA NA Cincinnati Ohio
21 11253 Williamson Rd NA NA Cincinnati Ohio
22 111 E 12th St NA NA Cincinnati Ohio
23 1910 Elm St NA NA Cincinnati Ohio
24 10 Fountain Square Plz NA NA Cincinnati Ohio
25 4003 Eastern Ave NA NA Cincinnati Ohio
26 1429 Race St NA NA Cincinnati Ohio
27 4831 Spring Grove Ave NA NA Cincinnati Ohio
28 4721 Red Bank Rd NA NA Cincinnati Ohio
29 2800 Woodburn Ave NA NA Cincinnati Ohio
30 <NA> NA NA Cincinnati Ohio
31 331 E 13th St NA NA Cincinnati Ohio
32 1660 Blue Rock St NA NA Cincinnati Ohio
33 3044 Harrison Ave NA NA Cincinnati Ohio
34 4811 Vine St NA NA Cincinnati Ohio
postal_code country longitude latitude phone
1 45233-1013 United States -84.70635 39.12640 5139750613
2 45226-1893 United States -84.41803 39.11996 5138714677
3 45244-3244 United States NA NA 5133079688
4 45214-2423 United States -84.52077 39.11257 6173685000
5 45224-3045 United States -84.54588 39.19279 5138823334
6 45202-6438 United States -84.51533 39.11323 5138276025
7 45230 United States NA NA 5132909434
8 45231-3559 United States -84.48055 39.21891 5138321422
9 45227-3925 United States -84.41349 39.11952 5138348789
10 45227-3926 United States -84.41349 39.11952 5138348789
11 45207-1007 United States -84.47213 39.14635 5137311130
12 45209-1132 United States -84.42397 39.15637 5138368733
13 45213 United States -84.41377 39.18858 5138368733
14 45249-1622 United States NA NA 5135620759
15 45202-4143 United States -84.50872 39.09630 5134212337
16 45244-2338 United States NA NA 5132402739
17 45213-1617 United States -84.42763 39.18228 5133664550
18 45202-4915 United States -84.51924 39.11837 5136736689
19 45214 United States -84.52224 39.11867 5136044527
20 45203 United States -84.53624 39.10593 2162021386
21 45241-2230 United States NA NA <NA>
22 45202 United States -84.51266 39.10853 5135799463
23 45202-7751 United States -84.51992 39.11720 5133811356
24 45202-3102 United States NA NA 5136211588
25 45226-1747 United States -84.43295 39.10920 5136155877
26 45202-7009 United States -84.51751 39.11133 <NA>
27 45232-1938 United States -84.51271 39.16812 5138535016
28 45277 United States -84.40434 39.15869 5134511763
29 45206-1793 United States -84.47684 39.12896 5132212337
30 45246 United States NA NA <NA>
31 45202-7307 United States -84.50944 39.11009 5135555555
32 45223-2554 United States -84.54196 39.16078 <NA>
33 45211-5752 United States -84.59843 39.14890 5136612337
34 45217-1217 United States -84.47462 39.20728 5138009560
website_url state street
1 http://www.13belowbrewery.com Ohio 7391 Forbes Rd
2 http://www.badtomsmithbrewing.com Ohio 4720 Eastern Ave
3 http://www.BigAshBrewing.com Ohio <NA>
4 http://www.samueladams.com Ohio 1625 Central Pkwy
5 http://www.brinkbrewing.com Ohio 5905 Hamilton Ave
6 http://www.christianmoerlein.com Ohio 1621 Moore St
7 http://www.deadlowbrewing.com Ohio <NA>
8 http://fibbrew.com Ohio 1445 Compton Rd
9 <NA> Ohio 7605 Wooster Pike
10 http://www.fiftywestbrew.com Ohio 7668 Wooster Pike
11 http://Listermannbrewing.com Ohio 1621 Dana Ave
12 http://www.madtreebrewing.com Ohio 3301 Madison Rd
13 http://www.madtreebrewing.com Ohio 5164 Kennedy Ave
14 http://www.marchfirstbrewing.com Ohio 7885 E Kemper Rd
15 http://www.moerleinlagerhouse.com Ohio 115 Joe Nuxhall Way
16 <NA> Ohio 4362 Mount Carmel Tobasco Rd
17 http://www.ninegiant.com Ohio 6095 Montgomery Rd
18 http://www.northernrow.com Ohio 111 W McMicken Ave
19 http://www.OffTrackBrewingCompany.com Ohio 227 Stark Street
20 <NA> Ohio 916 Dalton Ave
21 <NA> Ohio 11253 Williamson Rd
22 http://www.revelotr.com Ohio 111 E 12th St
23 http://www.rhinegeist.com Ohio 1910 Elm St
24 http://www.rockbottom.com Ohio 10 Fountain Square Plz
25 <NA> Ohio 4003 Eastern Ave
26 <NA> Ohio 1429 Race St
27 <NA> Ohio 4831 Spring Grove Ave
28 http://www.tapandscrew.com Ohio 4721 Red Bank Rd
29 http://www.woodburnbrewery.com Ohio 2800 Woodburn Ave
30 http://www.thirdeyebrewingcompany.com Ohio <NA>
31 http://www.3pointsbeer.com Ohio 331 E 13th St
32 http://www.artifactbeer.com Ohio 1660 Blue Rock St
33 http://www.westsidebrewing.com Ohio 3044 Harrison Ave
34 http://www.wiedemannbeer.com Ohio 4811 Vine St
After running this code, we now have a list of the breweries in Cincinnati, as well as all their classification that was available on the Open Brewery API. This API can search for more than just breweries based off location, but I have found that to be the most applicable practice.