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

HTTP: Pass along the api version for all request methods #12839

Merged
merged 1 commit into from
Apr 7, 2017

Conversation

blowery
Copy link
Contributor

@blowery blowery commented Apr 5, 2017

Previously, we would only pass it along for GET requests. This allows POST to also use api versions other than v1.

Previously, we would only pass it along for GET requests. This allows POST to also use api versions other than v1.
@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] S Small sized issue label Apr 5, 2017
@blowery blowery requested review from samouri and dmsnell April 5, 2017 20:53
@blowery blowery added Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Apr 5, 2017
@samouri
Copy link
Contributor

samouri commented Apr 5, 2017

Why does the check for GET exist at all? Can't all requests (GET/POST/ etc ) use query params?

@blowery
Copy link
Contributor Author

blowery commented Apr 5, 2017

Why does the check for GET exist at all? Can't all request (GET/POST/ etc ) use query params?

They can indeed. I was trying to make the smallest diff, as I wasn't sure why we were excluding query params from non-GET requests.

@samouri
Copy link
Contributor

samouri commented Apr 5, 2017

I'm okay with shipping this as-is because it solves a current bug, but I'd like to ideally figure out the answer to #12839 (comment) from @dmsnell

@blowery
Copy link
Contributor Author

blowery commented Apr 5, 2017

I'm happy to wait on it, I have this patch on the PR I'm working on.

@dmsnell
Copy link
Member

dmsnell commented Apr 7, 2017

Looks good to me @blowery! :shipit:

I tested the /plans data (it's a GET anyway) and it worked fine. I don't think we have any POSTs yet passing the apiVersion. note, however, that this will soon change as we need to also allow apiNamespace

@blowery
Copy link
Contributor Author

blowery commented Apr 7, 2017

@dmsnell there's one other quirk I uncovered while working on #12703; for a post, you must pass along a truthy body for the apiVersion to take. If you don't, compact ends up changing the parameter order to wpcom.js and things don't work. so

http( {
  method: 'POST',
  path: '/foo'
  apiVersion: '1.2',
} );

needs to be

http( {
  method: 'POST',
  path: '/foo'
  apiVersion: '1.2',
  body: {},
} );

to work as expected. Might want to address that when we add apiNamespace support.

@blowery blowery merged commit c07c97b into master Apr 7, 2017
@blowery blowery deleted the fix/http/allow-apiversion-on-non-get branch April 7, 2017 14:59
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 7, 2017
@dmsnell
Copy link
Member

dmsnell commented Apr 7, 2017

Might want to address that when we add apiNamespace support.

thanks @blowery - it's possible that @donnapep might have addressed this too in one of her PRs but I can't remember for sure

@donnapep
Copy link
Contributor

donnapep commented Apr 7, 2017

@blowery The change @dmsnell is referring to is PR #12135. It involved the removal of the passing of an empty object in the body param. POST wasn't working at all before that change. Thx.

bperson added a commit that referenced this pull request Apr 27, 2017
…n the `query`

wpcom's `req.post` has the signature: `params, [query], body, [callback]` which means positionnal arguments will move around based on the function's arity:

4: `params, query, body, callback`
3: `params, query, body` or `params, body, callback`
2: `params, body`

With that in mind, the use of `compact` in the data-layer considerably complexifies the situation, as we can hit those various arities for many combinations of arguments. This tries to simplify the process while fixing a few edge cases already encountered in a few past PRs (#12135, #12839):

If you want to pass `formData` (in `params`) with an `apiVersion` (in `query`), you NEED to pass a `body`, but any truth-y body will overwrite the `formData` in the HTTP request. This disqualifies the usage of `compact` as you - sometimes - want to pass a false-y values. (PR #12135)

If you want to just pass an `apiVersion` (in `query`), you need - at least - another argument to have an arity of 3, which means you need to pass an empty body (PR #12839)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework [Size] S Small sized issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants