Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 325 additions & 1 deletion .builderrules
Original file line number Diff line number Diff line change
@@ -1 +1,325 @@
Make sure when generating with MUI components look at the examples in src/* for correct usage of this code on the specific MUI versions we use and patterns we want to replicate.
Make sure when generating with MUI components look at the examples in src/* for correct usage of this code on the specific MUI versions we use and patterns we want to replicate.

When doing any thing with user data, use this internal API of ours:

# Users API

A RESTful API for managing user data, built with Cloudflare Workers and D1 database.

## Base URL

```
https://user-api.builder-io.workers.dev/api
```

## Authentication

No authentication required for public endpoints.

## Endpoints

### List Users

Returns a paginated list of users with optional search and sorting capabilities.

```
GET /users
```

#### Query Parameters

| Parameter | Type | Default | Description |
| --------- | ------- | ------------ | -------------------------------------------------------- |
| `page` | integer | 1 | Page number for pagination |
| `perPage` | integer | 10 | Number of results per page |
| `search` | string | - | Search users by first name, last name, email, or city |
| `sortBy` | string | "first_name" | Field to sort results by |
| `span` | string | "week" | Time span view ("week" or "month") - affects page offset |

#### Supported Sort Fields

- `name.first` - Sort by first name
- `name.last` - Sort by last name
- `location.city` - Sort by city
- `location.country` - Sort by country
- `dob.age` - Sort by age
- `registered.date` - Sort by registration date

#### Example Request

```bash
curl "https://user-api.builder-io.workers.dev/api/users?page=1&perPage=20&search=john&sortBy=name.first"
```

#### Example Response

```json
{
"page": 1,
"perPage": 20,
"total": 500,
"span": "week",
"effectivePage": 1,
"data": [
{
"login": {
"uuid": "test-uuid-1",
"username": "testuser1",
"password": "password"
},
"name": {
"title": "Mr",
"first": "John",
"last": "Doe"
},
"gender": "male",
"location": {
"street": {
"number": 123,
"name": "Main St"
},
"city": "New York",
"state": "NY",
"country": "USA",
"postcode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.006
},
"timezone": {
"offset": "-05:00",
"description": "Eastern Time"
}
},
"email": "[email protected]",
"dob": {
"date": "1990-01-01",
"age": 34
},
"registered": {
"date": "2020-01-01",
"age": 4
},
"phone": "555-0123",
"cell": "555-0124",
"picture": {
"large": "https://example.com/pic1.jpg",
"medium": "https://example.com/pic1-med.jpg",
"thumbnail": "https://example.com/pic1-thumb.jpg"
},
"nat": "US"
}
]
}
```

### Get User

Retrieve a specific user by UUID, username, or email.

```
GET /users/:id
```

#### Parameters

| Parameter | Type | Description |
| --------- | ------ | ----------------------------- |
| `id` | string | User UUID, username, or email |

#### Example Request

```bash
curl "https://user-api.builder-io.workers.dev/api/users/testuser1"
```

### Create User

Create a new user.

```
POST /users
```

#### Request Body

```json
{
"email": "[email protected]",
"login": {
"username": "newuser",
"password": "securepassword"
},
"name": {
"first": "New",
"last": "User",
"title": "Mr"
},
"gender": "male",
"location": {
"street": {
"number": 456,
"name": "Oak Avenue"
},
"city": "Los Angeles",
"state": "CA",
"country": "USA",
"postcode": "90001"
}
}
```

#### Required Fields

- `email`
- `login.username`
- `name.first`
- `name.last`

#### Example Response

```json
{
"success": true,
"uuid": "generated-uuid-here",
"message": "User created successfully"
}
```

### Update User

Update an existing user's information.

```
PUT /users/:id
```

#### Parameters

| Parameter | Type | Description |
| --------- | ------ | ----------------------------- |
| `id` | string | User UUID, username, or email |

#### Request Body

Include only the fields you want to update:

```json
{
"name": {
"first": "Updated"
},
"location": {
"city": "San Francisco"
}
}
```

#### Example Response

```json
{
"success": true,
"message": "User updated successfully"
}
```

### Delete User

Delete a user from the system.

```
DELETE /users/:id
```

#### Parameters

| Parameter | Type | Description |
| --------- | ------ | ----------------------------- |
| `id` | string | User UUID, username, or email |

#### Example Response

```json
{
"success": true,
"message": "User deleted successfully"
}
```

## Error Handling

All errors return appropriate HTTP status codes with a JSON error response:

```json
{
"error": "Error message here"
}
```

### Common Status Codes

- `200` - Success
- `201` - Created
- `400` - Bad Request
- `404` - Not Found
- `405` - Method Not Allowed
- `500` - Internal Server Error

## CORS

The API supports CORS with the following headers:

- `Access-Control-Allow-Origin: *`
- `Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS`
- `Access-Control-Allow-Headers: Content-Type`

## Rate Limiting

No rate limiting is currently implemented.

## Examples

### Search for users named "John"

```bash
curl "https://user-api.builder-io.workers.dev/api/users?search=john"
```

### Get users sorted by age

```bash
curl "https://user-api.builder-io.workers.dev/api/users?sortBy=dob.age"
```

### Get page 2 with 50 results per page

```bash
curl "https://user-api.builder-io.workers.dev/api/users?page=2&perPage=50"
```

### Create a new user

```bash
curl -X POST https://user-api.builder-io.workers.dev/api/users \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"login": {"username": "janesmith"},
"name": {"first": "Jane", "last": "Smith"}
}'
```

### Update a user's city

```bash
curl -X PUT https://user-api.builder-io.workers.dev/api/users/janesmith \
-H "Content-Type: application/json" \
-d '{"location": {"city": "Boston"}}'
```

### Delete a user

```bash
curl -X DELETE https://user-api.builder-io.workers.dev/api/users/janesmith
```
Loading