angularpostmanhttprequest

How can I do an http-request with a post method to an API in Angular 9


This is the first time I'm trying to do that and I don't know exactly how to start, if someone can guide me that would be very help full. I'm trying to do a login and if I want it to work a I have to do an http request with a post method to the API and will return me the information I need, but when I tried said Error 404 with URL, I tried with Postman and said other error that I will let below . I'm not telling that someone have to do it for me, just need someone to tell how can I start.

Error that Postman said:

{
    "type": "error",
    "message": "please make sure your meet the following field requirements",
    "check": 0,
    "passed": false,
    "requirements": [
        [
            "Identifier",
            {
                "is_required": true,
                "requires_value": true,
                "min_length": 1,
                "max_length": 150
            }
        ],
        [
            "Password",
            {
                "is_required": true,
                "requires_value": true,
                "min_length": 1,
                "max_length": 60
            }
        ]
    ]
}

Solution

  • here's a sample code doing post request

    let headers = new Headers({'Content-Type': 'application/json'});  
    headers.append('Authorization','Bearer <your auth here>')
    let options = new RequestOptions({headers: headers});
    const body = { username, password }; // will depend on how your api will accept
     return this.http.post(APIname,body,options)
      .map(this.extractData)
      .catch(this.handleError);