82 | Breakfast Stout | ![]() |
88 | Xingu Black Beer | ![]() |
76 | Rye on Rye (2015) | ![]() |
86 | English Barleywine | ![]() |
88 | Endothermic (Buffalo Trace) | ![]() |
Liquid Provisions | ![]() |
Weihenstephaner Helles | ![]() |
Weihenstephaner Helles | ![]() |
Weihenstephaner Helles | ![]() |
Orval Trappist Ale | ![]() |
TheBeerSpot API Code Examples
This page shows a couple of examples how you can access TheBeerSpot API to reference our data and also publish infomation on behalf of the users.
You can check out references for all of the calls you can make to the TheBeerSpot API on our reference page.
In this example, I am going to do a search for a beer called darkness, I will list the request and print the results using JQuery.
In my application, I am going to gather the data and send a POST to TheBeerSpot API, resuesting a search for any beers named darkness. Notice that I am limiting the results to 5 to keep this example basic and clean. You'll need to make sure you swap DEV_API_KEY with your API Key. <html> <head> <title>Test</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#beer_search").click(function(){ $.post("http://www.thebeerspot.com/api/search", { "function" : "beer" , "dev_key" : "DEV_API_KEY" , "search_term" : "darkness", "limit" : "5" }, function(response) { $.each(response, function() { $.each(this, function(name, value) { // add each item to a div on the page $("#display").append(name + " : " + value + "<br />"); }); // throw a line break at the end of each item $("#display").append("<br />"); }); }); }) }); </script> </head> <body> <input type="button" id="beer_search" value="Search Beer Darkness"/> <div id="display"></div> </body> </html> Here are the results from that search
beer_id : 1317 beer : Heart Of Darkness brewery_id : 629 brewery : Magic Hat Brewing Company style : Oatmeal Stout abv : beer_url : http://www.thebeerspot.com/beer/info/magic-hat-brewing-company/heart-of-darkness beer_id : 5513 beer : Slipping Into Darkness brewery_id : 630 brewery : Magnolia Pub & Brewery style : American Brown Ale abv : beer_url : http://www.thebeerspot.com/beer/info/magnolia-pub-and-brewery/slipping-into-darkness beer_id : 12277 beer : Darkness brewery_id : 944 brewery : Surly Brewing Company style : Russian Imperial Stout abv : 10.30 beer_url : http://www.thebeerspot.com/beer/info/surly-brewing-company/darkness beer_id : 13877 beer : Retreating Darkness brewery_id : 667 brewery : Minneapolis Town Hall Brewery style : American Porter abv : beer_url : http://www.thebeerspot.com/beer/info/minneapolis-town-hall-brewery/retreating-darkness beer_id : 16442 beer : Barrel Aged Darkness brewery_id : 944 brewery : Surly Brewing Company style : Russian Imperial Stout abv : 10.30 beer_url : http://www.thebeerspot.com/beer/info/surly-brewing-company/barrel-aged-darkness |
In this example, Ive already recieved the unique ID for Darkness in the last query and I want to "Drink" it on behalf of the user. This example will also use JQuery to post and display the results.
This example assumes that you have already sent the user to http://www.thebeerspot.com/api/me and have their USER_API_KEY plugged into your application. You'll need to make sure you swap DEV_API_KEY with your API Key. <html> <head> <title>Test</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#drink_beer").click(function(){ $.post("http://www.thebeerspot.com/api/update", { "function" : "drink_beer" , "dev_key" : "DEV_API_KEY" , "user_key" : "USER_API_KEY" , "beer_id" : "12277", "post_forum" : "on", "comment" : "This beer is awesome!", "test_mode" : "on", }, function(response) { $("#display").html(response["message"]); }); }) }); </script> </head> <body> <input type="button" id="drink_beer" value="Drink Beer Darkness"/> <div id="display"></div> </body> </html> Here are the results from that action. Since I left test_mode = on, the results include the test was a success. If you turn test_mode = off, it will just say Success! and the drink will be logged.
Test Mode Success! |