make a http options request in javascript

Here are examples of making an HTTP OPTIONS request in JavaScript using different libraries:

Using XMLHttpRequest:

index.tsx
const xhr = new XMLHttpRequest();
xhr.open('OPTIONS', 'https://example.com/api');
xhr.send();
94 chars
4 lines

Using fetch:

index.tsx
fetch('https://example.com/api', {
  method: 'OPTIONS'
});
59 chars
4 lines

Using axios:

index.tsx
axios.options('https://example.com/api');
42 chars
2 lines

gistlibby LogSnag