'convert curl to angular 12 Http request
How to covert curl https://api.stripe.com/v1/coupons -u sk_test_51L0g7yIrxFS2pGNOV1amLmGXMi0KatOjReDerQFeYE0jrIJZRaVEcODVN4KrMtx9BB2H7LJs5RSIZp8A0fybjgXh00Tma1Mkvt: this to angular http request
Solution 1:[1]
First you should see what method the coupons use. Its get or post? Second you should check more about HttpClient in angular documentation and finally you need to implement the Authentication mechanism.
For example if it is a get method and you have the token you will implement a service like this:
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from '/src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class StripeService {
constructor(private http : HttpClient) { }
public getCoupons() : any {
let headers = new HttpHeaders({
'Authorization': 'Bearer ' + environment.stripeKey,
});
const options = { headers: headers };
return this.http.get('https://api.stripe.com/v1/coupons', options);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Neter |
