Sp-dev-docs: Error using SPHttpClientConfigurations with the SPHttpClient

Created on 23 Jan 2017  路  6Comments  路  Source: SharePoint/sp-dev-docs

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Enhancement / Suggestion
  • [ ] Additional article idea

Expected or Desired Behavior

Using the SPHttpClient should work as described in the release notes.

Observed Behavior

When trying to use the SPHttpClient passing SPHttpClientConfigurations.v1 as the configuration, the browser throws an error Cannot read property 'v1' of undefined.

Steps to Reproduce

  • create new web part using React
  • add import { SPHttpClientConfigurations } from '@microsoft/sp-http';
  • in the render method add this.context.spHttpClient.get('/_api/web', SPHttpClientConfigurations.v1);
  • $ gulp serve --nobrowser
  • open hosted workbench and add the web part to canvas

    • error is displayed in the console

Most helpful comment

It turns out it's due to a typo in the documentation (that has been fixed). The correct usage is:

import { SPHttpClient } from '@microsoft/sp-http';

this.context.spHttpClient.get('/_api/web', SPHttpClient.configurations.v1);

All 6 comments

I got this in a couple of tenants as well. Is it that the RC0 bits haven't fully landed in all the tenants yet?

Worked fine on other tenants.

It turns out it's due to a typo in the documentation (that has been fixed). The correct usage is:

import { SPHttpClient } from '@microsoft/sp-http';

this.context.spHttpClient.get('/_api/web', SPHttpClient.configurations.v1);

This one is interesting. @VesaJuvonen I see you have made the edit to the docs. Could we get more info on which method of specifying the config is recommened? As @pgonzal has recommened using SPHttpClientConfigurations.v1 here https://github.com/SharePoint/sp-dev-docs/issues/44

When writing new code, our intent is for you to always specify the most recent version (i.e. "v" followed by the largest integer that is defined). This should give you all the recommended features, and disable any deprecated features.

When reusing code, e.g. copying snippets from the internet, you should not change the version number unless you are explicitly doing the work to migrate/retest the code.

That is the main reason why we introduced these configurations. (You can also use overrideWith() to customize the configuration, but personally I believe that is a rare edge case. In most cases you can achieve what you need by using the normal options.)

i am facing some issues with Alert notification,

error in javascript

thanks in advance

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karishmaTCS picture karishmaTCS  路  3Comments

byrongits picture byrongits  路  3Comments

waldekmastykarz picture waldekmastykarz  路  3Comments

waldekmastykarz picture waldekmastykarz  路  3Comments

mikeparkie picture mikeparkie  路  3Comments