If LDS doesn’t support the object you are looking to use, or if you want to use another Salesforce API, write an Apex class.
Calling a Salesforce API or a third-party API typically requires authentication and authorization using OAuth 2.0. Some APIs also make their data available without authentication and authorization for demonstration purposes, such as with the Google APIs Explorer. We recommend that you check the third-party API documentation for usage details.
If you need to include authentication headers in your calls, use the Apex
To make a call to a third-party API, you must first add the third-party URL to the Trusted URLs page in Setup. If you're fetching data from
https://www.example.com/items/v1/brands, add the base URL
https://www.example.com/ as a trusted URL.
Use the Fetch API to make third-party API calls. For example, you can make HTTP requests from your Lightning web component with the Fetch API and then parse JSON responses with the
The Fetch API returns a promise, which is useful when you're working with async requests. Use the
fetch() method to make a request and fetch a resource. The
catch() method is called only when the request fails entirely, such as when the user is offline, or when the request times out. To handle a 4XX or 5XX error, check the
response.status property using
then() or within the
- Salesforce Help: Manage Trusted URLs
- Salesforce Developers' Blog: Working with CORS and CSP to Call APIs from LWC
- Mozilla Developer Network: The WebSocket API