REST API

  const { createClient } = require("@astrajs/rest");

  // create an Astra client
  const astraClient = await createClient({
      astraDatabaseId: process.env.ASTRA_DB_ID,
      astraDatabaseRegion: process.env.ASTRA_DB_REGION,
      username: process.env.ASTRA_DB_USERNAME,
      password: process.env.ASTRA_DB_PASSWORD,
  });

  const basePath = "/api/rest/v2/KEYSPACES/<namespace>/collections/<collectionName>";

  // get a single user by document id
  const { data, status } = await astraClient.get(`${basePath}/<documentId>`);

  // get a subdocument by path
  const { data, status } = await astraClient.get(`${basePath}/<documentId>/<subdocument>/<subdocument>`);

  // search a collection of documents
  const { data, status } = await astraClient.get(${basePath}, {
    params: {
      where: {
        name: { $eq: "<documentId>" }
      }
    }
  });

  // create a new user without a document id
  ----
  const { data, status } = await astraClient.post(${basePath}, {
    name: "<documentId>",
  });
  ----

  // create a new user with a document id
  const { data, status } = await astraClient.put(`${basePath}/<documentId>`, {
    name: "cliff",
  });

  // create a user subdocument
  const { data, status } = await astraClient.put(`${basePath}/<documentId>/<subdocument>`, {
    title: "new blog",
  });

  // partially update user
  const { data, status } = await astraClient.patch(`${basePath}/<documentId>`, {
    name: "cliff",
  });

  // delete a user
  const { data, status } = await astraClient.delete(`${basePath}/<documentId>`);