Your first request
import { Tabs, TabItem } from ‘@astrojs/starlight/components’
The fastest way to use MassiCloud is via the JavaScript SDK. Let’s install it and make a request.
Install the SDK
Create a client
Create a file (e.g. src/lib/massi.js):
import { createClient } from '@massicloud/client'
export const massi = createClient({ url: 'https://api.massicloud.dz/v1/YOUR-PROJECT-SLUG', key: 'mc_anon_YOUR_KEY_HERE', stage: 'production', // db: 'main' ← optional, defaults to 'main'})Replace YOUR-PROJECT-SLUG and the key with values from your project. You can find both on the API Keys page in the portal.
The
stagefield tells MassiCloud which environment to talk to. Thedbfield is optional — it defaults to ‘main’, which is the database name auto-created with your project. If you’ve added more databases to your stage, usedb: 'other-name'here, or switch ad-hoc withmassi.db('other-name').
Sign up a user
import { massi } from './lib/massi'
const { data, error } = await massi.auth.signUp({ email: 'test@example.dz', password: 'something-secure',})
if (error) { console.error('Sign up failed:', error.message)} else { console.log('Signed up:', data.user.email)}Run this and the user is created in your auth.users table. The returned data contains the user record AND an access_token you can use to make authenticated requests.
Query a table
Let’s create a table from the portal first:
- Go to the explorer for your
maindatabase in theproductionstage - Click New table → name it
notes - Add columns:
id(uuid, primary key),title(text),user_id(uuid) - Save
Now from your code:
// Insert a noteconst { data: note } = await massi .from('notes') .insert({ title: 'Hello MassiCloud' }) .single()
// Read it backconst { data: notes } = await massi .from('notes') .select('*') .order('id', { ascending: false })
console.log(notes)Done. You’ve just created and queried real data through MassiCloud.