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

Data Layer: Allow setting apiNamespace in requests #13022

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Apr 12, 2017

See #10942
Replaces #11280

Certain API requests need to specify an apiNamespace query parameter
which is used to dispatch the request on the WordPress.com servers to
the right kind of API: WordPress.com API, WordPress wp-api, etc...

This change introduces the new parameter and checks to make sure that we
don't accidentally set both values. Previously in #10942 this
duplication happened and all requests in the HTTP layer failed.

This PR is much less ambitious than #11280 which builds a request
validation service into the HTTP layer itself. This merely adds the
parameter and safety check in actions#http() but that seems sufficient
for now and it leaves further validation up to wpcom.js down the line.

Testing

Nothing currently uses the apiNamespace in the data layer (because this introduces it) but to test we should smoke-test the existing stuff. Reader tag lists and the plans page is a good test.

cc: @retrofox @gwwar @samouri

P.S. It was my intention to build on the work @retrofox did in #11280 but I felt like the changes were much bigger than we needed and this is a nice incremental approach without introducing a lot more.

@see #10942
Replaces #11280

Certain API requests need to specify an `apiNamespace` query parameter
which is used to dispatch the request on the WordPress.com servers to
the right kind of API: WordPress.com API, WordPress wp-api, etc...

This change introduces the new parameter and checks to make sure that we
don't accidentally set both values. Previously in #10942 this
duplication happened and all requests in the HTTP layer failed.

This PR is much less ambitious than #11280 which builds a request
validation service into the HTTP layer itself. This merely adds the
parameter and safety check in `actions#http()` but that seems sufficient
for now and it leaves further validation up to `wpcom.js` down the line.

cc: @retrofox @gwwar @jake
@dmsnell dmsnell added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 12, 2017
@matticbot matticbot added the [Size] L Large sized issue label Apr 12, 2017
@matticbot
Copy link
Contributor

it( 'should set the apiVersion', () => {
const request = http( { apiVersion: 'v1' } );

expect( request ).to.have.deep.property( version, 'v1' );
Copy link
Contributor

@samouri samouri Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've never seen .deep.property before. very cool

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm preferring this in order to keep the test focused. only check for the thing that's under test and not everything else, also handle cases easily when the properties don't exist ("prop doesn't exist" rather than "threw an error")

Copy link
Contributor

@blowery blowery Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1 isn't a valid version. should be just plain old 1. I know it doesn't really matter for the test, but it's misled me more than twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. I saw your comment then forgot about it. I'll try to update here in the tests before merging. it's as good of a PR as any I suppose to fix that.

body,
method,
path,
query: method === 'GET' ? { ...query, ...version } : version,
Copy link
Contributor

@samouri samouri Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line isn't immediately obvious to me.
Cant a non GET request have a query?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coming soon in #13028

@dmsnell dmsnell merged commit 6218581 into master Apr 24, 2017
@dmsnell dmsnell deleted the update/data-layer/allow-apiNamespace branch April 24, 2017 23:56
@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 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Size] L Large sized issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants