0

My DELETE API on swagger is accepting an array of ids to delete. Like this:

[
  42
]

I have following code in angular v15. I am not getting how to pass an array of ids as a body to this delete API.

deleteProduct(productId: number): Observable<any> {

    let frequencyArray = JSON.parse("[2023]");

    return this.http

      .delete(this.baseUrl + "api/Product/deleteproduct", frequencyArray)

      .pipe(map((data) => data));

  }

Above code is giving an error:

Media type unsupported

I have searched a lot of things, but I am not getting any solution.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
HarrY
  • 607
  • 4
  • 14

1 Answers1

0

From the HttpClient class:

delete<T>(url: string, options?: {
    headers?: HttpHeaders | {
        [header: string]: string | string[];
    };
    context?: HttpContext;
    observe?: 'body';
    params?: HttpParams | {
        [param: string]: string | number | boolean | ReadonlyArray<string | number | boolean>;
    };
    reportProgress?: boolean;
    responseType?: 'json';
    withCredentials?: boolean;
    body?: any | null;
}): Observable<T>;

so you need to pass the body data in the option array.

Example .delete(this.baseUrl + "api/Product/deleteproduct", {body: frequencyArray})

giacomoto
  • 91
  • 4