Spoonancular API Library is a library to work with Spoonancular API.
- Install
npm install spoonacular-api-library - Import specific method
import { randomRecipe } from 'spoonacular-api-library'
- Execute a desired endpoint class with chosen HTTP method (get/post/put/delete...)
randomRecipe.get().then((response) => { console.log(response) })
- You can pass extra options, see axios config format for available properties. Be careful, you are able to override default options. See example below:
const extraConfig = { params: { ID: 12345 } }; randomRecipe.get(extraConfig).then((response) => { console.log(response) })
import { randomRecipe } from 'spoonacular-api-library'
randomRecipe.get().then((response) => {
console.log(response)
})If you want to extend this library, you need to configure your local environment. Follow these steps:
- Make sure that you have already installed node.js and npm package manager.
- Install all dependencies by running
npm install - Start your local dev environment with
npm run dev. It will run webpack in the watch mode, so the codebase will be recompiled when any change in the code will be detected. Everything will be compiled todistfolder. You can check the console for any errors. - Run
npm run lintto check the code style. - Write and run tests. You can find them in the
testfolder. You can run tests withnpm run test - You can use
npm run buildto build the library without the watch mode.
Spoonancular API provides mainly the GET request method for all of the endpoints, but my goal was to provide a scalable library, where we will be allowed to extend it by any of the HTTP methods or endpoint path.
In the codebase you can find already prepared mixins for GET and POST methods. But if you need, you can extend it by any method you want.
If you need to add another HTTP method, you can check the difference between already existing methods and create your own. You can find them in src/requestMixins directory.
If you want to add a new endpoint path, you can check already existing route, it's placed in src/routes directory. It all comes down to these steps:
- Check all allowed methods for the desired endpoint, and import corresponding mixins
- Define the endpoint path
- Pass imported mixins to applyMixins function
- Export your newly created endpoint (don't forget about index.ts)