This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Use HTTP OPTIONS Method

    Pete JohansonPete Johanson

    The HTTP OPTIONS method is used to request information about the communication options available for the target resource. The response may include an Allow header indicating allowed HTTP methods on the resource, or various Cross Origin Resource Sharing headers. The HTTP OPTIONS method is both safe and idempotent, as it is intended only for use in querying information about ways to interact with a resource.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 The HTTP options method is used to discover the ways that we can interact with a certain resource. Let's take a look at an options request to the Twilio API. Here, we can see the first line of our request uses the options method.

    00:17 Much like get and head, there is no request body, just the first line, and the request headers. The Twilio API has responded with a 200 family status code, as well as a set of response headers to provide us some additional metadata.

    00:30 The most frequently used response header when responding to options requests is the allow header. This header is used to indicate the allowed HTTP methods that can be used when interacting with our resource.

    00:41 Here, we can see the Twilio API is indicating that head, options, and get are the valid methods that can be used with this resource.

    00:51 In addition to the allow header, there are a set of headers being used to control cross-origin resource sharing, which is the mechanism that allows browsers to interact with APIs not hosted on their own origin server.

    01:05 For instance, if you have your own web application that would like to directly make API requests to Twilio from the browser.

    01:12 Here, we can see that Twilio is indicating that any origin server can be used with cross-origin resource sharing, as well as which HTTP headers can be included in those requests, and which HTTP headers in the response will be exposed to the browser client.

    01:28 To summarize, the HTTP options method is used to discover the ways we can interact with a certain resource, such as which HTTP methods are allowed, or the various controls of cross-origin resource sharing.

    Discuss

    Discuss