Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/client

Package Overview
Dependencies
Maintainers
6
Versions
993
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/client

Client for retrieving data from Sanity

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is @sanity/client?

@sanity/client is a JavaScript client for Sanity.io, a platform for structured content. It allows developers to interact with the Sanity content lake, enabling them to fetch, create, update, and delete documents, as well as perform queries and mutations.

What are @sanity/client's main functionalities?

Fetching Documents

This feature allows you to fetch documents from your Sanity dataset using GROQ queries. The example fetches all documents of type 'post'.

const sanityClient = require('@sanity/client');
const client = sanityClient({
  projectId: 'yourProjectId',
  dataset: 'yourDataset',
  useCdn: true
});

client.fetch('*[_type == "post"]').then(posts => {
  console.log(posts);
});

Creating Documents

This feature allows you to create new documents in your Sanity dataset. The example creates a new document of type 'post' with a title and body.

const sanityClient = require('@sanity/client');
const client = sanityClient({
  projectId: 'yourProjectId',
  dataset: 'yourDataset',
  useCdn: false
});

client.create({
  _type: 'post',
  title: 'Hello World',
  body: 'This is my first post!'
}).then(response => {
  console.log('Document created:', response);
});

Updating Documents

This feature allows you to update existing documents in your Sanity dataset. The example updates the title of a document with a specific ID.

const sanityClient = require('@sanity/client');
const client = sanityClient({
  projectId: 'yourProjectId',
  dataset: 'yourDataset',
  useCdn: false
});

client.patch('documentId')
  .set({ title: 'Updated Title' })
  .commit()
  .then(updatedDocument => {
    console.log('Document updated:', updatedDocument);
  });

Deleting Documents

This feature allows you to delete documents from your Sanity dataset. The example deletes a document with a specific ID.

const sanityClient = require('@sanity/client');
const client = sanityClient({
  projectId: 'yourProjectId',
  dataset: 'yourDataset',
  useCdn: false
});

client.delete('documentId').then(response => {
  console.log('Document deleted:', response);
});

Other packages similar to @sanity/client

Keywords

FAQs

Package last updated on 27 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc