fetch
Use the standard fetch function to retrieve data from the DatoCMS GraphQL Content Delivery API in a Svelte component.
<script>import { onMount } from 'svelte';const query = gql`query {blogPost {title}}`;let data = null;onMount(async () => {const response = await fetch('https://graphql.datocms.com/', {method: 'POST',headers: {'Content-Type': 'application/json',Authorization: "Bearer YOUR_API_TOKEN",},body: JSON.stringify({ query })})const json = await response.json()data = json.data;});</script><article>{#if data}<h1>{{ data.blogPost.title }}</h1>{/if}</article>sv
Make sure you replace YOUR_API_TOKEN
with an actual API token of your DatoCMS project. You can create a new one under "Settings > API Tokens".
You can learn everything you need regarding how to build GraphQL queries on our Content Delivery API documentation.