Make HTTP requests using curl
, the browser address bar, and AJAX for:
Use response data in future requests
Set up the client:
npm install
.We'll make requests of and receive responses from an HTTP server we'll set up together:
~/wdi/tmp
.jquery-ajax
branch within library-api
.We're now ready to make requests.
What's in a name?
AJAX at MDN.
The jQuery.ajax() interface.
Retrieve a list of books from the API
Entering http://localhost:3000/books
into the chrome address bar.
If not already installed in chrome, let's add a JSON formatting utility.
curl
is a command line utility for making http requests. We'll use curl to
retrieve the book collection.
Let's write that curl command into a script.
We'll take a stepped approach:
index.html
.assets/scripts/index.js
.assets/scripts/ui.js
.assets/scripts/library-api.js
.The A in AJAX stands for asynchronous. Let's explore some implications of asynchronous behavior.
Retrieve a book from the API
Entering http://localhost:3000/books/1
into the chrome address bar.
Entering http://localhost:3000/books/<integer>
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:
index.html
.assets/scripts/ui.js
.assets/scripts/library-api.js
.Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.