Skip to content

Commit 64cccab

Browse files
Merge pull request #35 from yash-pouranik/docs/refactor-readme
docs: refactor README, offload API docs, and implement unique Cyber N…
2 parents 227c512 + 2943ceb commit 64cccab

9 files changed

Lines changed: 233 additions & 208 deletions

File tree

API_USAGE.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# urBackend API Usage Guide 📖
2+
3+
This guide provides technical examples for interacting with the urBackend API. Once your project is created in the dashboard, use your **Public API Key** (for frontend) or **Secret API Key** (for backend) to make requests.
4+
5+
## Base URL
6+
7+
```
8+
https://api.urbackend.bitbros.in
9+
```
10+
11+
## 1. Authentication
12+
13+
Manage users for your own applications using urBackend's built-in auth system.
14+
15+
### Sign Up User
16+
```javascript
17+
await fetch('https://api.urbackend.bitbros.in/api/userAuth/signup', {
18+
method: 'POST',
19+
headers: {
20+
'Content-Type': 'application/json',
21+
'x-api-key': 'YOUR_API_KEY'
22+
},
23+
body: JSON.stringify({
24+
email: "user@example.com",
25+
password: "securePassword123",
26+
name: "John Doe" // Optional
27+
})
28+
});
29+
```
30+
31+
### Login User
32+
```javascript
33+
const res = await fetch('https://api.urbackend.bitbros.in/api/userAuth/login', {
34+
method: 'POST',
35+
headers: {
36+
'Content-Type': 'application/json',
37+
'x-api-key': 'YOUR_API_KEY'
38+
},
39+
body: JSON.stringify({
40+
email: "user@example.com",
41+
password: "securePassword123"
42+
})
43+
});
44+
const data = await res.json(); // Returns { token: "JWT_TOKEN", user: {...} }
45+
```
46+
47+
### Get Profile (Me)
48+
```javascript
49+
await fetch('https://api.urbackend.bitbros.in/api/userAuth/me', {
50+
method: 'GET',
51+
headers: {
52+
'x-api-key': 'YOUR_API_KEY',
53+
'Authorization': 'Bearer <USER_TOKEN>' // From login response
54+
}
55+
});
56+
```
57+
58+
## 2. Database API
59+
60+
Direct JSON document storage with no database management required.
61+
62+
### Get All Items
63+
```javascript
64+
// Replace :collectionName with your actual collection name (e.g., 'products')
65+
const res = await fetch('https://api.urbackend.bitbros.in/api/data/products', {
66+
headers: { 'x-api-key': 'YOUR_API_KEY' }
67+
});
68+
const data = await res.json();
69+
```
70+
71+
### Insert Data
72+
```javascript
73+
await fetch('https://api.urbackend.bitbros.in/api/data/products', {
74+
method: 'POST',
75+
headers: {
76+
'Content-Type': 'application/json',
77+
'x-api-key': 'YOUR_API_KEY'
78+
},
79+
body: JSON.stringify({
80+
name: "MacBook Pro",
81+
price: 1299,
82+
inStock: true
83+
})
84+
});
85+
```
86+
87+
### Update / Delete by ID
88+
```javascript
89+
const id = "DOCUMENT_ID";
90+
91+
// Update
92+
await fetch(`https://api.urbackend.bitbros.in/api/data/products/${id}`, {
93+
method: 'PUT',
94+
headers: {
95+
'Content-Type': 'application/json',
96+
'x-api-key': 'YOUR_API_KEY'
97+
},
98+
body: JSON.stringify({ price: 1199 })
99+
});
100+
101+
// Delete
102+
await fetch(`https://api.urbackend.bitbros.in/api/data/products/${id}`, {
103+
method: 'DELETE',
104+
headers: { 'x-api-key': 'YOUR_API_KEY' }
105+
});
106+
```
107+
108+
## 3. Storage API
109+
110+
Manage files and images with ease.
111+
112+
### Upload File
113+
```javascript
114+
const formData = new FormData();
115+
formData.append('file', fileInput.files[0]);
116+
117+
const res = await fetch('https://api.urbackend.bitbros.in/api/storage/upload', {
118+
method: 'POST',
119+
headers: { 'x-api-key': 'YOUR_API_KEY' },
120+
body: formData
121+
});
122+
const data = await res.json();
123+
// Returns { url: "...", path: "project_id/filename.jpg" }
124+
```
125+
126+
### Delete File
127+
```javascript
128+
await fetch('https://api.urbackend.bitbros.in/api/storage/file', {
129+
method: 'DELETE',
130+
headers: {
131+
'Content-Type': 'application/json',
132+
'x-api-key': 'YOUR_API_KEY'
133+
},
134+
body: JSON.stringify({
135+
path: "PROJECT_ID/filename.jpg"
136+
})
137+
});
138+
```
139+
140+
## 🔐 Security Best Practices
141+
142+
> [!IMPORTANT]
143+
> **Key Separation**:
144+
> - Use the **Publishable Key** (`pk_live_...`) for frontend requests (Read-Only).
145+
> - Use the **Secret Key** (`sk_live_...`) ONLY for backend/secure environments.

0 commit comments

Comments
 (0)