Comments (9)
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.
from cashew.
Can you please reproduce it on stackblitz?
from cashew.
Replicated on SB: https://stackblitz.com/edit/angular-ivy-n6csyb?file=src%2Fapp%2Fhello.component.ts
Also occuring on A11
Using jsonplaceholder as a fake api service
from cashew.
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 })
)
from cashew.
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.
from cashew.
I also had some issues today when I used the library the first time.
I wanted to create a PR, but when I further investigated the issue, I found the solution to this problem (which is inside the application code) :
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
from cashew.
Okay, nevermind my comment before.
Coming back to work topics, I need to see, that it is still not working correctly.
I recognized, that the request url to the api is not built correctly. This is what happens:
It builds a url in the format like this: <baseUrl>/api/v1/items?params=foo=bar&bar=foo
I don't know why, but it appends an additional params=
. Without, everything would work fine
from cashew.
- wrong types in
export declare function withCache(params?: Params): {
params: Params;
};
- in http.d.ts
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>;
- So
withCache
should return type as http.d.ts, so If I can't add auth headers is not useful - I think
withCache
should return HttpParams - using angular 11
from cashew.
The library now uses context.
from cashew.
Related Issues (20)
- withCache can not add Authorization header HOT 1
- Replace query params to http context
- Angular Universal - localstorage is undefined HOT 9
- Regression: Implicit strategy broken in v2? HOT 1
- Angular CLI reports library as CommonJS or AMD dependency HOT 3
- How to chain multiple HttpContext HOT 3
- Feature: specify max age for cached responses HOT 2
- Bug: empty observable returned when request is repeated inside it's subscriber
- TypeError when testing service with CacheBucket HOT 1
- Allow override of cache storage provider HOT 4
- Bug: When using LocalStorage for cache, clear() does not work HOT 1
- Feature: Dynamic storage target HOT 1
- Angular 14 support HOT 2
- feat: add modern provide* api-s HOT 11
- docs: cache then refresh data
- HttpHeaders are not handled HOT 1
- docs: compatability matrix? HOT 3
- Allow numeric values as keys HOT 1
- Update docs on how to configure cashew in module based Angular app
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cashew.