fetch()
Using the `fetch()` global function
nx.js implements the fetch()
global function for fetching data from the network. If you are familiar with the Fetch API, then you will find the nx.js fetch()
function very similar.
The following URL protocols are supported:
http:
- Fetch data from the network using the HTTP protocolhttps:
- Fetch data from the network using the HTTPS protocolblob:
- Fetch data from a URL constructed byURL.createObjectURL()
data:
- Fetch data from a Data URI (possibly base64-encoded)sdmc:
- Fetch data from a local file on the SD cardromfs:
- Fetch data from the RomFS partition of the nx.js applicationfile:
- Same assdmc:
Usage
The fetch()
function takes a URL as its first argument, and returns a Promise that resolves to a Response
object. The Response
object contains information about the fetched data, such as the status code, headers, and body.
You can also pass additional options to the fetch()
function to customize its behavior. For example, you can specify a method
to use for the request, or a body
to send along with the request.