0

How can I load data from azure web API into SPFx web part?

API:

https://someazuresite.azurewebsites.net/api

Code I am using currently:

this.props.context.spHttpClient.get(`https://someazuresite.azurewebsites.net/api`,  
          SPHttpClient.configurations.v1)  
          .then((response: SPHttpClientResponse) => {  
            response.json().then((responseJSON: any) => {  
              console.log(responseJSON);  
            });  
          }); 
3

1 Answer 1

1

If your web API is secured using Azure AD application, by using the AadHttpClient, you can easily connect to APIs secured by using Azure AD without having to implement the OAuth flow yourself.

Check this Microsoft official documentation for step by step tutorial for same: Connect to Azure AD-secured APIs in SharePoint Framework solutions

Also, check below SPFx samples developed and shared by community members which might help you with development of your SPFx web part:

  1. Call custom Web API secured with AAD from SharePoint Framework client-side web part
  2. Azure Active Directory implicit flow authentication samples

Update

Update from this post, use code like:

this.props.context.spHttpClient.get(`https://someazuresite.azurewebsites.net/api`,  
    SPHttpClient.configurations.v1)  
    .then((response: SPHttpClientResponse) => {  
        return response.json().then((responseJSON: any) => { 
            for(let index = 0; index < responseJSON.length; index++){
                console.log(responseJSON[index].Title);
            }
        });  
    }); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.