Skip to main content

Creating and Managing Content

In a social media app, content creation and management are crucial features. Tapestry provides powerful endpoints to handle these operations efficiently. This guide will walk you through creating, updating, and deleting posts using Tapestry's content endpoints.

Creating a Post

The first step in most social media apps is allowing users to create posts. This is achieved through the postContentCreate endpoint.

Here's an example of how to create a new post:

await fetch('https://api.usetapestry.dev/v1/contents/create?apiKey=YOUR_API_KEY', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
profileId: 'user123',
"properties": [
{
"key": "title",
"value": "My First Post"},{
"key": "url",
"value": "example.com/post1"},{
"key": "body",
"value": "Hello world!"
}
]
}),
})

In this example:

  • profileId represents the user creating the post
  • properties is an array of key-value pairs, where body is the text of the post

Updating a Post

Sometimes users may want to edit their posts. You can use the putContentUpdate endpoint for this purpose:

await fetch('https://api.usetapestry.dev/v1/contents/update?apiKey=YOUR_API_KEY', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: 'post123',
content: 'Updated content: Hello, world! This is my edited post.',
blockchain: 'Solana'
}),
})

Here, id is the unique identifier of the post you want to update.

Deleting a Post

To allow users to delete their posts, use the postContentDelete endpoint:

await fetch('https://api.usetapestry.dev/v1/contents/delete?apiKey=YOUR_API_KEY', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: 'post123',
blockchain: 'Solana'
}),
})

Again, id is the unique identifier of the post to be deleted.

Execution Methods

When creating, updating, or deleting content, you can specify an execution method. This determines how the transaction is processed on the blockchain. For more information on execution methods, see our Execution Methods documentation.

By leveraging these content endpoints, you can build a robust and interactive social media application on Tapestry. Remember to handle errors and implement appropriate user interfaces to create a seamless user experience.