API Tutorial: Spoonacular API for food and recipes

Jed Ng
Jed Ng
Jun 14 · 5 min read

Spoontacular’s Recipe-Food-Nutrition API offers access to more than 365,000 recipes, and nutritional information on better than 86,000 food items. It uses natural language processing to allow search queries such as “gluten free brownies without sugar,” if you’re into that sort of thing. This powerful API also offers various culinary solutions such as special dietary restriction search parameters, kitchen equipment visualization and more.

In this article, we will cover how to request recipes and their respective nutritional data

via Spoonacular’s Recipe-Food-Nutrition API with Rakuten RapidAPI using javascript and node.js.

Setup

To get started you’ll need

  1. Javascript editor and npm unirest package that will speed up code writing
  2. Rakuten RapidAPI account and the API key that comes with it

Getting the Javascript Cod

Rakuten RapidApi got you covered and packaged all the javascript code you need to work with the API in an easy unirest SDK, which is a library to simplify HTTP REST requests and save you time writing code.

Get started by installing the unirest package with the following command:

  1. npm install unirest — save

As soon as that’s done, you can start exploring the API. It’s safe to ignore the npm warn messages at this point if you see any.

Start with Signing Up to Rakuten RapidAPI

About Rakuten RapidAPI

Rakuten RapidAPI is the world’s largest API marketplace with 8,000+ third-party APIs and used by over 500,000 active developers. We enable developers to build transformative apps through the power of APIs. Find, test and connect to all the APIs you need in one place!

We’ve also got you covered with Spoonacular API access. You can try it, without leaving the browser, on the Spoonacular API page. You’ll need to sign up to get the API keys and make requests to the Spoonacular API. With these keys you’ll be able to make and authenticate the requests so we will know they come from you.

As soon as you sign-in with your account, the view above will be replaced with another view, where you can see your API keys (X-RapidAPI-Key) in the Request Headers section and a ready to copy the snippet of code at the right side.

Recipe-Food-Nutrition API Overview

Spoonacular provides through Rakuten RapidAPI multiple endpoint categories, each of which covers a specific feature that you can use:

  • Compute: Visualize food, recipe and nutritional information; convert measurements; visualize equipment, price breakdowns and more.
  • Extract: Extract recipes from websites; parse ingredients; analyze a recipe search query; analyze recipe instructions; detect food in text.
  • Search: Search for grocery items, recipes, nutritional data, food videos, wine pairings and more in all manner of variations.
  • Data: Get recipe and food information, food trivia and jokes and more.
  • Chat: Talk to a chatbot and get conversation suggestions.

Raid the Fridge in Style: Recipes for Ingredients on Hand

Imagine with me for a second that you are hungry, but you don’t want to go to the store.

We’re going to tackle this problem by using the Spoonacular API to find recipes for the ingredients we have on hand. Then, we’ll ask for nutritional information because what if someone needs to know their Weight Watcher Points for our snack? Finally, we’ll get a wine pairing, cause we have an extensive cellar and we get thirsty making all of these requests.

Let’s get started.

Getting Recipes:

Params:

Upon successful completion, the Recipe-Food-Nutrition API returns:

Code snippet:

Here, we will pass a GET request with our list of ingredients in order to ask for recipes that use those ingredients.

Getting Bulk Nutritional Data for Recipes:

Params:

Upon successful completion, the Recipe-Food-Nutrition API returns:

Code snippet:

Here, we are passing the body of the response from the GET Recipe by Ingredients call we made above. We are asking Spoonacular for nutritional information for each of the recipes it just gave us.

Getting Wine Pairing:

All that searching has left me parched, and I kind of want to dress up my Cheddar Apple Stackers at the same time. A wine pairing sounds like just the trick!

Params:

Upon successful completion, the Recipe-Food-Nutrition API returns:

Response Body:

Code Snippet:

Here, we’ve gone back to our ingredient, rather than a recipe, because Spoonacular’s wine pairing seems to prefer food or class of food, such as ‘T-bone steak,’ or ‘fish.’

That’s It

You are ready to integrate powerful recipe and nutrition features into your project. Feel free to use the code in your production applications and check the rest of the APIs on Rakuten RapidAPI to enhance your application even further. And if you haven’t yet gotten your fill, check out the many other food and nutrition APIs on our platform here.

About Rakuten RapidAPI

Rakuten RapidAPI is the world’s largest API marketplace with 8,000+ third-party APIs and used by over 500,000 active developers. We enable developers to build transformative apps through the power of APIs. Find, test and connect to all the APIs you need in one place!

Check out some of the world’s best APIs including Microsoft, Sendgrid, Crunchbase, and Skyscanner.

Facebook | LinkedIn | Twitter

Rakuten RapidAPI

We’re all about helping developers find and connect to APIs for their next killer app with our API Marketplace with over 8000 APIs and 500,000 active developer around the world.

Jed Ng

Written by

Jed Ng

Building API unicorn | Investor | Advisor @ Voxeet (exited)

Rakuten RapidAPI

We’re all about helping developers find and connect to APIs for their next killer app with our API Marketplace with over 8000 APIs and 500,000 active developer around the world.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade