1

This is how I need to send the request.

localhost:8080/api/user?id=53380&name=raj&start=1&rows=5

where id=53380&name=raj is one object.

Tried setting the param and send like below.

 let params: URLSearchParams = this.objToSearchParams(this.search); // this.search =  {id: 53380, name: raj}
 params.set("start", 1);
 params.set("rows", 5)

     return this._http.get('/api/user', {params: params})
                .map(response => response['result'])
                .catch(this.handleError);


 objToSearchParams(obj): URLSearchParams{
    let params: URLSearchParams = new URLSearchParams();
    for (var key in obj) {
        if (obj.hasOwnProperty(key))
            params.set(key, obj[key]);
    }
    return params;
 }

This doesn't sends any request this is the API call after executing this code

localhost:8080/api/user

there is no params send. How can I achieve this ? Do I need to manually convert one by one ?

user630209
  • 1,123
  • 4
  • 42
  • 93

1 Answers1

0

To do something like that :

getCustomerByCustomerName(customerName : string):Observable<Customer[]>{
    return this.http.get<Customer[]>(`${this.api.catchApiUrl()}Customer/GetCustomerByCustomerName?customerName=${customerName}`)
}

You can do that :

getCustomerByCustomerName(custName : string):Observable<Customer[]>{
    return this.http.get<Customer[]>(`${this.api.catchApiUrl()}Customer/GetCustomerByCustomerName`,{
      params : {
        customerName : custName
      }
    })
}

Try to do it parameter by parameter and if it works put it in an object.

I find this maybe you can find what you need.

user10863293
  • 770
  • 4
  • 11
  • 32