1.0.5 • Published 4 years ago

spoonacular-api-library v1.0.5

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

#Spoonacular API Library Spoonancular API Library is a library to work with Spoonancular API. All that you have to do is to install this library as a dependency and use already prepared methods, request the server.

##Getting started 1. Install

```
npm install spoonacular-api-library
```
  1. Import specific method
    import { randomRecipe } from 'spoonacular-api-library'
  2. Execute a desired with method (get/post/put/delete)
    randomRecipe.get().then((response) => {
      console.log(response)
    })
  3. 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)
    })

##Available endpoints ####randomRecipe #####Available methods: GET

import { randomRecipe } from 'spoonacular-api-library'

randomRecipe.get().then((response) => {
  console.log(response)
})

##Contribution If you want to extend this library, you need to configure your local environment. Follow these steps: 1. Make sure that you have already installed node.js and npm package manager. 2. Install all dependencies by running npm install 3. 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 to dist folder. You can check the console for any errors. 4. Run npm run lint to check the code style. 5. Write and run tests. You can find them in the test folder. You can run tests with npm run test 6. You can run npm run build to build the library without the watch mode.

###How to extend this library Spoonancular API provides mainly the GET request method for all 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 the most popular HTTP methods (get/post/put/delete). It's possible to extend any of the endpoints by any of the methods just by including the mixin on the composing step.

Add another HTTP method

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.

Add another endpoint path

If you want to add a new endpoint path, you can check already existing routes, they are placed in src/routes directory. It all comes down to these steps: 1. Check all allowed methods for the desired endpoint, and import corresponding mixins 2. Define the endpoint path 3. Pass imported mixins to applyMixins function 4. Export your newly created endpoint (don't forget about index.ts)

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago