How do I send a request with Authorization Bearer Header? [JavaScript/AJAX Code]

To send a request with the Bearer Token authorization header, you need to make an HTTP request and provide your Bearer Token with the "Authorization: Bearer {token}" header. A Bearer Token is a cryptic string typically generated by the server in response to a login request. The client must send this Bearer Token in the Authorization header on every request it makes to obtain a protected resource. For security reasons, Bearer Tokens are only sent over HTTPS (SSL). Click Send to execute the Bearer Token Authorization Header example online and see results. The JavaScript/AJAX code was automatically generated for the Authorization Bearer Header example.
How do I send a request with Authorization Bearer Header? [JavaScript/AJAX Code] Send
GET /echo/get/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Authorization: Bearer my token

Updated: Viewed: 15443 times
JavaScript/AJAX code for Authorization Bearer Header example

JavaScript/AJAX code for Authorization Bearer Header Example

This JavaScript/AJAX code snippet was generated automatically for the Authorization Bearer Header example.
<< Back to the Authorization Bearer Header example

What is HTTP?

HTTP is a network data transfer protocol used to transfer data between HTTP clients (browsers, mobile apps, etc.) and servers. HTTP is based on a client-server architecture and built on messages called requests and responses. The client generates a request and sends it to the server, where the server processes this request and generates a response by sending it back to the client.

What is the Authorization Header?

The Authorization request header includes credentials to authenticate the client on the server. HTTP provides a built-in framework for user authentication and controlling access to protected resources.

What is Bearer Authorization?

Bearer authentication (also called token authentication) is a mechanism used to authorize clients by sending a security token with every HTTP request we make to the server. The server usually generates a bearer token in response to a login request and sends it to the client. The client stores it on the user's device (for example, the browser can save the token in local storage). The client sends the bearer token back to the server on every request to the protected resource (in the Authorization header).

Bearer Token Authorization Syntax
GET /echo/get/json HTTP/1.1
Authorization: Bearer {token}
Host: reqbin.com

Where:
  • Authorization: standard HTTP authorization header
  • Bearer: indicates a bearer token authorization scheme

How to send a request with Bearer Authorization Header?

An example HTTP POST request with a Bearer Token authentication header that we send to the echo ReqBin URL:

Bearer Token Authentication Example
POST /echo/post/form HTTP/1.1
Authorization: Bearer {token}
Host: reqbin.com

[post data]

See also

Generate code snippets for JavaScript/AJAX and other programming languages

Convert your Authorization Bearer Header request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the JavaScript/AJAX code generator.