From the course: JavaScript: Ajax and Fetch
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Customize a fetch request - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Customize a fetch request
- [Insructor] Fetch allows you to create a well-organized request with a minimum of code. But sometimes APIs require a more finely grained HTTP request than what fits in a URL. By far the most common instance of this, is APIs that require one or more HTTP headers as part of your request. Fetch supports a second argument after the URL, which is an initialization object containing one or more arguments. This can include the HTTP method, your credentials, or a number of other options, including headers. To include headers, you use the headers properties name within the init object. And then specify an object as its value. This object includes each header name and value as a key value pair. Our HTTP request to SmartyStreets has been working fine, but if you read through the documentation, you'll notice that SmartyStreets prefers each request to include two specific HTTP headers. If they decide to enforce this down the line, my request might result in an error in the future, so I want to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.