-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpParams not being parsed on http Post correctly #32
Comments
Can you please reproduce it on stackblitz? |
Replicated on SB: https://stackblitz.com/edit/angular-ivy-n6csyb?file=src%2Fapp%2Fhello.component.ts Using jsonplaceholder as a fake api service |
Why you're not using a pojo? const params = {
api_key: "1234",
url: "https://google.com/"
};
this.http
.get(
"https://jsonplaceholder.typicode.com/todos/",
withCache({ ...params })
) |
The HttpParam object is an output from another component. All the services were given HttpParams by default. If cashew doesn't have a native way to convert them, I can just create a function to change httpparam to an object. Just wanted to check if I was missing something in cashew. If not, it's all good and we can close this out. |
I don't mind getting a PR that adds built-in support for it. If you can't, in the meantime, you can use a function to convert it. |
I also had some issues today when I used the library the first time. const params = new HttpParams();
params = params.append('context', context)
// w/o cashew
// const options = {params};
// example above ("wrong approach"):
// const options = withCache({...params});
// with cashew ("right approach"):
const options = withCache({params});
this.http.get(url, options).subscribe(); I also adjusted the Stackblitz example, which is now working as expected: https://stackblitz.com/edit/angular-ivy-erpgym?devtoolsheight=33&file=src/app/hello.component.ts |
Okay, nevermind my comment before. I recognized, that the request url to the api is not built correctly. This is what happens: I don't know why, but it appends an additional |
export declare function withCache(params?: Params): {
params: Params;
};
get<T>(url: string, options?: {
headers?: HttpHeaders | {
[header: string]: string | string[];
};
observe?: 'body';
params?: HttpParams | {
[param: string]: string | string[];
};
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
|
The library now uses context. |
I'm submitting a...
Current behavior
When doing a http POST with HttpParams calls wrong url.
The called url is
https://localhost:4200/api/search?updates=%5Bobject%20Object%5D&cloneFrom=&encoder=%5Bobject%20Object%5D&map=null
Expected behavior
Can pass a variable with HttpParams type into WithCache and correct url is called. HTTP call functions as normal. Cache is stored as per cashew localstorage.
Minimal reproduction of the problem with instructions
Given a this test code.
Cashew clearly tries to convert HttpParams to query string. Is there a specific object I should be passing?
Environment
The text was updated successfully, but these errors were encountered: