Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add recipes endpoint to get multiple recipes #10

Merged
merged 1 commit into from Feb 20, 2022

Conversation

nakyamurya
Copy link
Contributor

Hi!
I gave it a shot to create a endpoint to offer more flexible response.

Changes:

  • Add /recipes/ endpoint to get multiple recipes.
  • Query parameter (limit, offset) allows to vary how many recipes to be returned and skip rows in DB.

Sample request:

import requests
r = requests.get("http://localhost:8000/recipes/?limit=2&offset=5")
data = r.json()

Sample response:

{
    "status": 200,
    "results": [
        {
            "id": 14,
            "name": "Pumpernickel Bread II Recipe",
            "total_duration": 60,
            "ingredients": [
                "brown sugar",
                "cocoa powder",
                "salt",
                "cornmeal",
                "milk",
                "flour",
                "molasses",
                "bread",
                "yeast",
                "vegetable oil"
            ],
            "directions": "Mix well bread flour, rye flour, cornmeal, salt, yeast, cocoa, and brown sugar. Add milk, oil, and molasses. Mix thoroughly. When mixed well enough that the dough holds together, knead by hand 15-20 minutes.Cover, let rise in bowl 30 minutes. Punch down, form, and place into 9 1/2x5 inch pan. Cover with damp cloth and let rise about 1 hour.Bake in preheated 375 degree F (190 degrees C) oven 25 to 30 minutes, covering top with aluminum foil last 10 minutes."
        },
        {
            "id": 18,
            "name": "Light Oat Bread Recipe",
            "total_duration": 180,
            "ingredients": [
                "brown sugar",
                "water",
                "salt",
                "flour",
                "margarine",
                "oat",
                "yeast"
            ],
            "directions": "Add ingredients to bread machine pan in order recommended by your manufacturer. Use regular light setting."
        }
    ]
}

@Geometrein
Copy link
Collaborator

Looks cool! thanks for your valuable contributions. @MariiaSizova will review/test it and merge!

@MariiaSizova MariiaSizova merged commit f0d6bc3 into MariiaSizova:main Feb 20, 2022
@MariiaSizova
Copy link
Owner

MariiaSizova commented Feb 20, 2022

@nakyamurya Thank you very much for your contribution! I merged your code and modified it slightly. You can check the result breakfastapi.fun.
I thought that it is a bit odd to return recipes by order when we already have an option to return recipes by id. So I modified your function to return random N recipes where N can be defined using the path parameters.
For example this:

https://breakfastapi.fun/recipes/6

I also defined a request class where we can validate the requests sent to this endpoint.

@nakyamurya
Copy link
Contributor Author

@MariiaSizova Thank you for considering my PR! It makes sense to me!

@nakyamurya nakyamurya deleted the feature/get-multi branch February 20, 2022 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants