-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
RFC: Add HttpOptions to EntityActionOptions to allow finer control over HttpClient requests #3663
Comments
…trol over HttpClient requests (ngrx#3663)
…trol over HttpClient requests (ngrx#3663) added doco
Honestly, while i get your point of not oversharing information, my original usecase was to be able to access data from url‘s which deviate from the current pattern required by ngrx data in certain conditions, e.g. accessing subressources which do not work with query-parameters. so thats why passing in the action itself (which can be customized, i.e. extended to carry additional data as of how to retrieve data) would be a better solution in my case. so in my use-case is actually not about adding headers or query-parameters. but to actually alter the whole url which is otherwise not possible with a simple httpcustomizer curently provided. but i know it‘s hard to find a balance flexibility and clear cut apis. i just think passing in the action is probably still better in my eyes. |
i see that #3093 deals with the exact use-case i was mentioning. yeah that‘s the issue i thought could be resolved by passing in a customized action into the data-service… so yes, sorry for interfering with your rfc. |
Don't be @smorandi, thanks for taking the time to comment :) I'm in the process of migrating to ngrx/data and I have similar endpoints I will have to deal with, like As I'm in control of these endpoints I'll probably use routes like Not much help if you can't change your api though. Although, if this RFC goes ahead as is I think you'd be able to use the For example, you need to overrided one of the E.g.
I think there's still other work needed to ensure the reducers handle success correctly, but does this get you close to what you want? |
yes sure it would be fine, as long as i can pass „arbitrary“ data into the data service it would be absolutely fine. using httpoptions -> httpparams as the container for additional information works certainly well enough. |
…trol over HttpClient requests (ngrx#3663) added doco - rewrite to be non-breaking
…trol over HttpClient requests (ngrx#3663) - Removed redundant property of HttpOptions - Added warnings re deprecation of queryParams in getWithQuery - make HttpOptions type serializable
…trol over HttpClient requests (ngrx#3663) - fixed warnig message and made it coniitional
Please mention breaking changes like this in CHANGELOG.md |
Which @ngrx/* package(s) are relevant/related to the feature request?
ngrx/data
Information
Currently it is difficult to influence http requests sent in response to dispatched
EntityAction
s. Simple requirements such as adding query parameters or headers require multiple ngrx/data classes to be overriden and provided. Often those implementing ngrx/data have an existing api they need to integrate with, and endpoints that require more than just an id/entity/list of entities to function correctly.Proposing to add
HttpOptions
toEntityActionOptions
that support finer control over the http requests executed by Data Services.Change summary:
EntityActionOptions
property:HttpOptions
:HttpOptions
from anEntityAction
toDataService
requestsEntityCollectionDataService
api to be updated to include optionalHttpOptions
in each supported requestDefaultDataService
to be updated to passHttpOptions
along to theHttpClient
requests. Both httpParams and httpHeaders are the correct type for the constructors of their respective angular classes:HttpParams
andHttpHeaders
as at Ng14.getWithQuery
should continue to acceptQueryParams
in arg 1 so as not to break clients.HttpOptions
includes passing Http Params and is available in arg 2.If specified, http params in
HttpOptions
will replace those in arg 1QueryParams
.QueryParams
has been annotated as deprecated, however removing the first arg would be a breaking change so looking for guidance from the core team on whether deprecation is required here. It might be possible to retiregetWithQuery
and usegetAll
with HttpOptions instead. Food for thought.QueryParams
type has been updated to reflect the (now exported)HttpParamsOptions
fromObject
type def (addsboolean
,number
, and their respectiveReadOnlyArray
types).Related Issues
This issue proposed passing the entire EntityAction to data services. This comment by @wardbell outlines the solution.
I've taken a different approach for a couple of reasons.
HttpContext
feature, and possibly (for the sake of requirements that can't be anticipated) auserDefinedOptions: any
property toHttpOptions
so user's can pass whatever they want.this discussion deals with adding url parameters which this feature does not address, however it also mentions support for pagination which could be supported by the ability to add query parameters.
Describe any alternatives/workarounds you're currently using
The workaround to this would be having to provide custom implementations of various ngrx data classes and factories. This ability also offers an alternative to hijacking the EntityAction
tag
property.I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: