Skip to content
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

Allow fetching as POST requests #76

Open
shaungrady opened this issue Aug 26, 2020 · 4 comments
Open

Allow fetching as POST requests #76

shaungrady opened this issue Aug 26, 2020 · 4 comments

Comments

@shaungrady
Copy link

shaungrady commented Aug 26, 2020

Given that the URL as passed in as a string to beforeFilters, it's unable to be modified.

The use case for us is that we have an endpoint that we need to use HTTP POSTs for reads due to very long filter strings. beforeFilters allows the HTTP method to be changed to POST, and allows for translating the query string to a POST body, but we're unable to strip the query string from the URL.

I'd imagine the fix for this would be nesting the url and options filter args under an object, which would be a breaking change. I'd be happy to write a PR if it's decided that this would be an acceptable feature.

Another approach might be to check to see if the method has changed from GET to POST/PUT/PATCH and do that translation and query string removal automatically.

@richmolj
Copy link
Contributor

Hey @shaungrady, thanks for the great write-up. This has come up before. I wonder if we might instead add this as a static boolean property on the model class. scope.ts already has a reference to this.model, so this.model.klass.whateverThePropertyIsNamed should get us what we need. Then it's just a matter of swapping this code depending on the property value.

I like this approach because it's a simple flag we can point to whenever the use case comes up, instead of requiring middleware and breaking compatibility. What do you think?

@shaungrady
Copy link
Author

I think that approach makes a lot of sense 👌
Maybe a flag named getAsPost to stay consistent with the SpraypaintBase.patchAsPost flag?

@richmolj
Copy link
Contributor

How about fetchAsPost?

@shaungrady shaungrady changed the title Allow beforeFilters to modify URL Allow fetching as POST requests Aug 27, 2020
@shaungrady
Copy link
Author

shaungrady commented Aug 27, 2020

What serialization behavior for the body would we be looking for?

Do we want to re-parse the query params—note the stringified array…

{ "data": {
	"filters": {
		"foo": "bar,baz"
	}
}}

… or use the straight JsonapiQueryParams format?

{ "data": {
	"filters": {
		"foo": ["bar", "baz"]
	}
}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants