Official JavaScript SDK for interacting with the Manifest API.
📚 Full JS SDK documentation: manifest.build/docs
npm i @mnfst/sdk
Use the SDK directly in your frontend:
import Manifest from '@mnfst/sdk'
// Initialize client (default: http://localhost:1111, or pass a custom base URL)
const manifest = new Manifest('https://example.com')
// Perform CRUD operations...
const posts = await manifest.from('posts').find()
// Create a new item in the "pokemons" entity.
const newPokemon = await manifest.from('pokemons').create({
name: 'Pikachu',
type: 'electric',
level: 3
})
// Get all users.
const users = await manifest.from('users').find()
// Get cat with ID `2c4e6a8b-0d1f-4357-9ace-bdf024681357`.
const cat = await manifest
.from('cats')
.findOneById('2c4e6a8b-0d1f-4357-9ace-bdf024681357')
// Updates the Pokemon item with ID `a1b2c3d4-e5f6-4789-abcd-ef0123456789`.
const newPokemon = await manifest
.from('pokemons')
.update('a1b2c3d4-e5f6-4789-abcd-ef0123456789', {
name: 'Raichu',
type: 'electric',
level: 8
})
// Patches the Pokemon item with ID `a1b2c3d4-e5f6-4789-abcd-ef0123456789`.
const newPokemon = await manifest
.from('pokemons')
.patch('a1b2c3d4-e5f6-4789-abcd-ef0123456789', {
level: 5
})
// Delete the cat with ID `550e8400-e29b-41d4-a716-446655440000`.
const deletedCat = await manifest
.from('cats')
.delete('550e8400-e29b-41d4-a716-446655440000')
// Fetch entities with 2 relations.
const cities = await manifest.from('cities').with(['region', 'mayor']).find()
// Fetch nested relations.
const cities = await manifest
.from('cities')
.with(['region', 'region.country', 'region.country.planet'])
.find()
// Get all cats that belong to owner with id 3f2504e0-4f89-11d3-9a0c-0305e82c3301.
const cats = await manifest
.from('cats')
.with(['owner'])
.where('owner.id = 3f2504e0-4f89-11d3-9a0c-0305e82c3301')
.find()
// Get all cats that have an owner with name "Jorge".
const cats = await manifest
.from('cats')
.with(['owner'])
.where('owner.name = Jorge')
.find()
// Store a new player with relations Team and Skill.
const newPlayer = await manifest.from('players').create({
name: 'Mike',
teamId: 'e4d5c6b7-a890-4123-9876-543210fedcba',
skillIds: [
'12345678-1234-5678-9abc-123456789012',
'3f2504e0-4f89-11d3-9a0c-0305e82c3301'
]
})
// Replaces the whole skill relations by the new skillIds array.
await manifest.from('players').update('e4d5c6b7-a890-4123-9876-543210fedcba', {
name: 'Mike',
teamId: 'e4d5c6b7-a890-4123-9876-543210fedcba',
skillIds: [
'12345678-1234-5678-9abc-123456789012',
'3f2504e0-4f89-11d3-9a0c-0305e82c3301'
]
})
// Updates the team without changing the skills or the name.
await manifest.from('players').patch('e4d5c6b7-a890-4123-9876-543210fedcba', {
teamId: '9b2fff23-ec93-4b48-9322-bbd4b6b5b123'
})
Full documentation:
- CRUD: manifest.build/docs/crud
- Auth: manifest.build/docs/authentication
- File upload: manifest.build/docs/upload
- Custom endpoints: manifest.build/docs/endpoints
To contribute to the Manifest JS SDK, please read first the general contributing.md file.
The best way to work with the SDK is using the /sandbox
folder that hosts a minimalistic Angular app that imports the Manifest SDK. You can run the app with the following commands:
cd sandbox
npm install
npm run start