Make HTTP requests using curl
and AJAX to:
- Delete a specific resource.
Use response data in future requests
- Fork and clone this repository.
- Create and checkout a new branch (training).
- Install dependencies with
npm install
.
You can access the same web server that we set up during jquery-ajax-get-collection. Just leave the server running at the same port.
We'll make requests of and receive responses from an HTTP server we'll set up together:
- Open a new terminal (window or tab).
- Change into
~/wdi/tmp
. - Fork and clone library-api-guide and follow installation instructions listed there.
- Once installed, checkout a
jquery-ajax
branch withinlibrary-api
.
We're now ready to make requests.
Delete a book from the API
First let's ensure we can get a book with a specific id.
Enter http://localhost:4741/books/1
into the chrome address bar to retreive a single book with id=1
We can also use curl to retrieve one book at a time.
We'll use curl with the DELETE http verb to signify to our API that we want to delete the book
Why can't we delete a book using the browser address bar?
Let's write that curl command into a script.
Again, take a stepped approach:
- Add a new form with text input for a book id to the form in
index.html
. - Add a Delete button to the form
- Retrieve the value of the id, if any, in the submit handler.
- Branch on that value in the submit handler.
- Add a delete single book success and fail handler to
assets/scripts/books/ui.js
. - Add a delete single book method to
assets/scripts/books/api.js
. - Invoke the delete single book method from the submit handler passing the success and fail callbacks.
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.