How do I use these Web API's search function?

How do I set up my program to search this database? Free API | TheCocktailDB.com

For example:

https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita

I don’t understand why “margarita” is at the end of this url. I’m lost

Probably best to start with the WebAPI video tutorials. They are a good introduction to using APIs and take you through step by step. The WebAPI help page on the wiki is also helpful.

The basic steps are to:

  1. Set up WebAPI in the Advanced section of the blocks menu.
  2. Use the “Set API’s URL” function to create the URL based on parameters you capture in your programme.
  3. Call the webAPI and then parse the response so that you can get the specific information you need.
  4. Use the outcome of step 3 to do something in your programme.

Looking at the Free API | TheCocktailDB.com page, it looks like you have lots of options how to search their database depending what you are trying to do. You probably need to first decide what that is and then see if there is a search method they have listed that lets you do that.

WebAPI is an advanced topic and it takes a bit of time to learn how to do it. There is no real shortcut to learning about it through the videas and wiki.

Hope that helps.

2 Likes

https:// www.thecocktaildb.com /api/json/v1/1/ search.php ?s=margarita

Let’s dissect that URL a bit:
https:// is the protocol. https:// is the secure (encrypted) form of http://.
www.thecocktaildb.com is the domain name - it maps to the location (IP address) of the server.
/api/json/v1/1/ once upon a time told the webserver what folder you wanted. Lately, there might not really be folders (it might all be virtual), but anyway, directions to tell the server what to do.
search.php is the file the server is running (again, with some caveats) to serve up your request.
? separates the URL part from the query part. Everything that comes after the ? is passing in some variables to the server, in this case, that the variable “s” (perhaps short for ‘search’) has the value “margarita”. If you wanted to search for a mojito instead, you could replace the margarita with mojito.

That’s the easy part. The harder part will be figuring out how to parse what the server gives back. You’ve got good links provided for how to do that, above. :slight_smile:

2 Likes

For JSON parsing (pulling apart the result you get from the Web API server), check out my tutorial video:

2 Likes

sorry… meant to post my comment on a different thread!

1 Like