Make HTTP requests using curl
, the browser address bar, and AJAX for:
- 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.
Retrieve a book from the API
Entering http://localhost:4741/books/1
into the chrome address bar.
We'll use curl to retrieve the one book at a time.
Let's write that curl command into a script.
Again, take a stepped approach:
- Add a text input for a book id to the form in
index.html
. - Retrieve the value of the id, if any, in the submit handler.
- Branch on that value in the submit handler.
- Add a single book success and fail handler to
assets/scripts/ui.js
. - Add a single book retrieval method to
assets/scripts/library-api.js
. - Invoke the single book retrieval 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 [email protected].