Coder Social home page Coder Social logo

python-p4-building-post-patch-delete-api-lab's Introduction

Building a POST/PATCH/DELETE API Lab

Learning Goals

  • Build an API to handle GET, POST, PATCH, and DELETE requests.

Key Vocab

  • Application Programming Interface (API): a software application that allows two or more software applications to communicate with one another. Can be standalone or incorporated into a larger product.
  • HTTP Request Method: assets of HTTP requests that tell the server which actions the client is attempting to perform on the located resource.
  • GET: the most common HTTP request method. Signifies that the client is attempting to view the located resource.
  • POST: the second most common HTTP request method. Signifies that the client is attempting to submit a form to create a new resource.
  • PATCH: an HTTP request method that signifies that the client is attempting to update a resource with new information.
  • DELETE: an HTTP request method that signifies that the client is attempting to delete a resource.

Instructions

This is a test-driven lab. Run pipenv install to create your virtual environment and pipenv shell to enter the virtual environment. Then run pytest -x to run your tests. Use these instructions and pytest's error messages to complete your work in the server/ folder. Make sure to test your routes in Postman as you progress.

In this application, we'll be working on a familiar JSON API to get a list of bakeries and their baked goods. We have two models, bakeries and baked goods, in a one-to-many relationship. The migrations are already set up. Here's a reminder of what the ERD for these tables looks like:

Bakeries ERD

You can pick up where we left off by entering the following commands in the server/ directory:

$ flask db upgrade
$ python seed.py
$ python app.py
  • Define a POST block inside of a /baked_goods route that creates a new baked good in the database and returns its data as JSON. The request will send data in a form.
  • Define a PATCH block inside of the /bakeries/<int:id> route that updates the name of the bakery in the database and returns its data as JSON. As with the previous POST block, the request will send data in a form. The form does not need to include values for all of the bakery's attributes.
  • Define a DELETE block inside of a /baked_goods/<int:id> route that deletes the baked good from the database and returns a JSON message confirming that the record was successfully deleted.

Once all of your tests are passing, commit and push your work using git to submit.

Examples

POST /baked_goods

POST request with form data for a baked good's name, price, and bakery_id

PATCH /bakeries/<int:id>

PATCH request with form data for a bakery's name

DELETE /baked_goods/<int:id>

DELETE request for baked good by ID


Resources

python-p4-building-post-patch-delete-api-lab's People

Contributors

professor-ben avatar pgill97 avatar jlboba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.