Skip to main content

Posts

Showing posts with the label set header to HttpHeaders

How to set a custom header on the request?

How to set a custom header on the request? To set a custom header on the request, firstly we need to instantiate HttpHeaders() object and pass ('header',   'value') into a function. let headers = new HttpHeaders (). set ( 'Content-Type' , 'text' ); In the above example we set “Content-Type” header value to be “text” and the default header “Content-Type” is – “application/json” It is of type immutable Map so if you assign a new value it will reinitialize the object. let requestHeaders = new HttpHeaders (). set ( 'Content-Type' , 'application/json' ); requestHeaders = requestHeaders . set ( 'authorization' , 'Bearer ' + token ); We can also append headers by chaining HttpHeaders() constructor and will look like this- let requestheaders = new HttpHeaders (). set ( 'Content-Type' , 'application/json' )                     . set ( 'authorization' , 'Bearer '...

What Are Angular HttpHeaders?

What Are HttpHeaders? The Http Headers is immutable Map and each and every set() returns a new instance and applies the changes with lazy parsing. An immutable set of Http headers, with lazy parsing. HttpHeaders Constructor - constructor ( headers ?: string | { [name: string]: string | string [];}); Imports HttpHeaders from - import { HttpHeaders } from '@angular/common/http' ; HttpHeaders class contains the list of methods - 1.       has() - Checks for existence of header by given name. 2.       get() - Returns the first header that matches given name. 3.       keys() - Returns the names of the headers 4.       getAll() - Returns list of header values for a given name. 5.       append() - Append headers by chaining. 6.       set() -   To set a custom header on the request for a given name ...

Angular 5 JWT Login Authentication Examples Step by Step

What Is JWT?   The JWT is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA. How to setup a simple login page using Angular 5 and JWT authentication? In Annular 5, the following steps are used to building authentication and authorization for RESTful APIs and applications. I hope it might help you all- 1.         The users send their credentials to the server which is verified by the database credentials. If everything is verified successfully, the JWT is sent back to them. 2.         The JWT is saved in the user's browser in local storage or in a cookie and so on. 3.         The presence of a J...