> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: fetch(url: string, options: WixFetchRequest)

# Method package: wixFetch

# Method menu location: wixFetch --> fetch

# Method Link: https://dev.wix.com/docs/velo/apis/wix-fetch/fetch.md

# Method Description:

Retrieves the specified resource from the network using HTTPS.

The `fetch()` function fetches an HTTPS resource from the network. It returns
 a Promise that resolves to a [`WixFetchResponse`](https://dev.wix.com/docs/velo/apis/wix-fetch/wix-fetch-response/introduction.md)
 object representing the HTTP response to the request.

 Responses with an HTTP status code in the ranges 2xx, 4xx, and 5xx are
 considered fulfilled. Use the [`httpResponse.ok`](https://dev.wix.com/docs/velo/apis/wix-fetch/wix-fetch-response/ok.md)
 property to confirm that the HTTP request was successful with a response
 code in the 2xx range.

 The optional `WixFetchRequest` object contains information about an HTTPS request.
 Additional functionality is available in each of the respective [Fetch API implementations](https://dev.wix.com/docs/velo/apis/wix-fetch/introduction.md).

 > **Notes:**
 > Some common errors when using the `fetch()` function are described here along with possible solutions.
 >
 > - You can usually tell if you are experiencing these issues by checking your browser's console using the [browser's developer tools](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools).
 > - Certain [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) (Cross-Origin Resource Sharing) requests are restricted when originating from a browser. Usually, GET requests and certain POST requests can be made
 >   from your site's **Public**, **Page**, or **Site** code. All other requests need to be made from your site's **Backend** code. If you are experiencing an issue with a `fetch()`
 >   call due to a CORS restriction, move the `fetch()` call to the backend as described in [Accessing 3rd-Party Services](https://support.wix.com/en/article/accessing-3rd-party-services#backend-service-call).
 > - Because all Wix sites use HTTPS, you can't request HTTP content from a service in your site's code.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Get a resource

```javascript
import {fetch} from 'wix-fetch';

// ...

fetch("https://someapi.com/api/someendpoint", {"method": "get"})
  .then( (httpResponse) => {
    if (httpResponse.ok) {
      return httpResponse.json();
    } else {
      return Promise.reject("Fetch did not succeed");
    }
  } )
  .then(json => console.log(json.someKey))
  .catch(err => console.log(err));
```

## Post data to a resource

```javascript
import {fetch} from 'wix-fetch';

// ...

fetch( "https://someapi.com/api/someendpoint", {
  "method": "post",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "body": "somekey=somevalue"
} )
  .then( (httpResponse) => {
    if (httpResponse.ok) {
      return httpResponse.json();
    } else {
      return Promise.reject("Fetch did not succeed");
    }
  } )
  .then( (json) => console.log(json.someKey) )
  .catch(err => console.log(err));
```

## Get a resource and the response information

```javascript
import {fetch} from 'wix-fetch';

// ...

fetch("https://someapi.com/api/someendpoint", {"method": "get"})
  .then( (httpResponse) => {
    let url = httpResponse.url;
    let statusCode = httpResponse.status;
    let statusText = httpResponse.statusText;
    let headers = httpResponse.headers;
    let bodyUsed = httpResponse.bodyUsed;
    if (httpResponse.ok) {
      return httpResponse.json();
    }
    else {
      return Promise.reject("Fetch did not succeed");
    }
  } )
  .then( (json) => {
    console.log(json.someKey);
  } )
  .catch( (err) => {
    console.log(err);
  } );
```

## Get a resource

```javascript
import { fetch } from 'wix-fetch';

// GET call using fetch
export async function getRandomGreeting() {
  const response = await fetch('https://velo-examples.wixsite.com/training-tester/_functions/randomgreeting');
  if(response.ok) {
    const json = await response.json();
    return json.greeting;
  } else {
    return Promise.reject("Fetch did not succeed");
  }
}

```

## Post data to a resource

```javascript
import { fetch } from 'wix-fetch';

// POST call using fetch
export async function postGreeting(language, greeting) {
  const jsonBody = {
    language,
    greeting
  };
  
  const fetchOptions = {
    method: 'post',
    headers: 'application/json',
    body: JSON.stringify(jsonBody)
  };

  const response = await fetch('https://velo-examples.wixsite.com/training-tester/_functions/greeting', fetchOptions); 
  return response.json();
}

```

---