Getting started with Sanity as a headless CMS
Written by Knut Melvær
Sanity is the perfect companion for when you want to get started with the JAMstack, or just need API for your project. In this tutorial you’ll learn how to get started with using Sanity — from configuring the React editor with JavaScript, to querying the API and migrating the content datasets.
If you find yourself in need of some backend, the chances are that Sanity is one of the quickest ways to get started without later punishing you. Spin up a new Sanity project for your weekend project. For that time you need an API to test something quickly. Or you can use it for more serious stuff. For example, when you need a conduit between a legacy system and the technology you prefer to use. And when you need humans to be in control of digital content, Sanity has an open source editor, that you can configure with simple JavaScript, customize with React, and host anywhere you want – be it Netlify, Now, or on Sanity’s cloud.
It's one of the best and well thought-through content backends I've worked with, and that's why I now work for Sanity – and loving every single day of it.
Watch the video "Getting Started with Sanity"
You can create as many free Sanity projects you want and get a lot done within the developer tier, and the pricing is transparent and flexible.
You should be up and running within minutes – just use your Google- or GitHub-login, accept the Terms of Service, and that's it. Begin with installing the Sanity CLI and initiate a new project with:
npm i -g @sanity/cli && sanity init
The instructions of the sanity init
command will take you through creating a project and downloading the Sanity Studio locally. If you run sanity start
in your project folder, the CLI will open a local server with hot-module reloading so you can configure it without having to refresh the browser manually. The Studio is always connected to the hosted real-time backend, which means, that as soon as you begin working with content in it, that content will also be available and queryable in the API. In other words, it's swift to get a project going where your editor can begin working with content, that you can fetch and use in your project.
It can be useful to try some of the preconfigured templates the first time, but to show you how easy it is to configure the Studio, let me show you the code for a simple post entry:
Internal server error