🎮 Bloxd API Scripts & Examples

1. Get All Posts

GET /v1/posts

Retrieve all posts from the API

// JavaScript Fetch
fetch('https://api.bloxd.io/v1/posts', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_PUBLIC_KEY'
    }
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));
// cURL
curl -H "apikey: YOUR_PUBLIC_KEY" \
     -H "Content-Type: application/json" \
     https://api.bloxd.io/v1/posts

2. Create New Post

POST /v1/posts

Create a new post with content

// JavaScript Fetch
fetch('https://api.bloxd.io/v1/posts', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_SECRET_KEY'
    },
    body: JSON.stringify({
        title: 'My Bloxd Adventure',
        content: 'Just started playing Bloxd.io!',
        category: 'gaming',
        tags: ['bloxd', 'minecraft', 'fun']
    })
})
.then(res => res.json())
.then(data => console.log('Post created:', data))
.catch(err => console.error(err));
// cURL
curl -X POST https://api.bloxd.io/v1/posts \
  -H "apikey: YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My Bloxd Adventure",
    "content": "Just started playing Bloxd.io!",
    "category": "gaming",
    "tags": ["bloxd", "minecraft", "fun"]
  }'

3. Get Post by ID

GET /v1/posts/:id

Retrieve a specific post by ID

// JavaScript Fetch
const postId = '12345';
fetch(`https://api.bloxd.io/v1/posts/${postId}`, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_PUBLIC_KEY'
    }
})
.then(res => res.json())
.then(data => console.log('Post:', data))
.catch(err => console.error(err));
// cURL
curl -H "apikey: YOUR_PUBLIC_KEY" \
     https://api.bloxd.io/v1/posts/12345

4. Update Post

PUT /v1/posts/:id

Update an existing post

// JavaScript Fetch
const postId = '12345';
fetch(`https://api.bloxd.io/v1/posts/${postId}`, {
    method: 'PUT',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_SECRET_KEY'
    },
    body: JSON.stringify({
        title: 'Updated Title',
        content: 'Updated content goes here',
        status: 'published'
    })
})
.then(res => res.json())
.then(data => console.log('Post updated:', data))
.catch(err => console.error(err));
// cURL
curl -X PUT https://api.bloxd.io/v1/posts/12345 \
  -H "apikey: YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated Title",
    "content": "Updated content goes here",
    "status": "published"
  }'

5. Delete Post

DELETE /v1/posts/:id

Delete a post

// JavaScript Fetch
const postId = '12345';
fetch(`https://api.bloxd.io/v1/posts/${postId}`, {
    method: 'DELETE',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_SECRET_KEY'
    }
})
.then(res => res.json())
.then(data => console.log('Post deleted:', data))
.catch(err => console.error(err));
// cURL
curl -X DELETE https://api.bloxd.io/v1/posts/12345 \
  -H "apikey: YOUR_SECRET_KEY" \
  -H "Content-Type: application/json"

6. Get User Stats

GET /v1/users/:userId/stats

Retrieve player statistics

// JavaScript Fetch
const userId = 'user123';
fetch(`https://api.bloxd.io/v1/users/${userId}/stats`, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_PUBLIC_KEY'
    }
})
.then(res => res.json())
.then(data => console.log('User stats:', data))
.catch(err => console.error(err));
// cURL
curl -H "apikey: YOUR_PUBLIC_KEY" \
     https://api.bloxd.io/v1/users/user123/stats

7. Search Posts

GET /v1/posts/search?q=query&limit=10

Search for posts with query parameters

// JavaScript Fetch
const searchQuery = 'bloxd tips';
const limit = 10;
const url = new URL('https://api.bloxd.io/v1/posts/search');
url.searchParams.append('q', searchQuery);
url.searchParams.append('limit', limit);

fetch(url, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_PUBLIC_KEY'
    }
})
.then(res => res.json())
.then(data => console.log('Search results:', data))
.catch(err => console.error(err));
// cURL
curl -H "apikey: YOUR_PUBLIC_KEY" \
     "https://api.bloxd.io/v1/posts/search?q=bloxd%20tips&limit=10"

8. Like/Unlike Post

POST /v1/posts/:id/like

Like or unlike a post

// JavaScript Fetch
const postId = '12345';
fetch(`https://api.bloxd.io/v1/posts/${postId}/like`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_SECRET_KEY'
    },
    body: JSON.stringify({
        action: 'like' // 'like' or 'unlike'
    })
})
.then(res => res.json())
.then(data => console.log('Like action:', data))
.catch(err => console.error(err));

9. Get Post Comments

GET /v1/posts/:id/comments

Retrieve comments on a post

// JavaScript Fetch
const postId = '12345';
fetch(`https://api.bloxd.io/v1/posts/${postId}/comments`, {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_PUBLIC_KEY'
    }
})
.then(res => res.json())
.then(data => console.log('Comments:', data))
.catch(err => console.error(err));

10. Add Comment to Post

POST /v1/posts/:id/comments

Create a new comment on a post

// JavaScript Fetch
const postId = '12345';
fetch(`https://api.bloxd.io/v1/posts/${postId}/comments`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'apikey': 'YOUR_SECRET_KEY'
    },
    body: JSON.stringify({
        content: 'Great post! This is really helpful.',
        mentions: ['@user123']
    })
})
.then(res => res.json())
.then(data => console.log('Comment created:', data))
.catch(err => console.error(err));