Oblivion is a Go-based playground project that implements a REST API for managing buckets and their associated keys and values. The project demonstrates how to build a CRUD-based REST API using only Go's standard libraries and SQLite for data persistence.
- Bucket Management: Create, retrieve, list, and delete buckets.
- Key-Value Management: Store, retrieve, update, and delete key-value pairs within buckets.
- Querying: Search for keys based on criteria.
- Validation: Input validation for bucket names, field names, and data types.
- Error Handling: Structured error responses with HTTP status codes and error descriptions.
The project is organized into the following directories:
api/: Contains the REST API handlers and routing logic.bucket/: Implements the business logic for bucket operations.httprouter/: Provides a lightweight HTTP router and response utilities.model/: Defines the data models used in the application.repo/: Implements the repository layer for data persistence using SQLite.valid/: Contains validation logic for input data.apperror/: Defines application-specific error types and handling.
GET /v1/buckets
Response:
[
"bucket1",
"bucket2"
]POST /v1/buckets
Request Body:
{
"name": "people",
"schema": [
{
"field": "id",
"type": "string",
"not-null": true,
"indexed": true
},
{
"field": "first_name",
"type": "string",
"not-null": true,
"indexed": false
}
]
}Response:
{
"name": "people",
"schema": [
{
"field": "id",
"type": "string",
"not-null": true,
"indexed": true
},
{
"field": "first_name",
"type": "string",
"not-null": true,
"indexed": false
}
]
}GET /v1/buckets/{bucket}
Response:
{
"name": "people",
"schema": [
{
"field": "id",
"type": "string",
"not-null": true,
"indexed": true
},
{
"field": "first_name",
"type": "string",
"not-null": true,
"indexed": false
}
]
}DELETE /v1/buckets/{bucket}
Response: 204 No Content
GET /v1/buckets/{bucket}/keys/{key}
Response:
{
"id": "id1",
"first_name": "John",
"last_name": "Doe"
}PUT /v1/buckets/{bucket}/keys/{key}
Request Body:
{
"id": "id1",
"first_name": "John",
"last_name": "Doe"
}Response: 204 No Content
DELETE /v1/buckets/{bucket}/keys/{key}
Response: 204 No Content
GET /v1/buckets/{bucket}/keys?field=value
Response:
[
"key1",
"key2"
]- Install Go (version 1.22 or later).
- Clone the repository:
git clone https://github.com/jjmrocha/oblivion.git cd oblivion - Run the application:
go run main.go
- The server will start on
http://localhost:9090.
You can use the provided test.http file to test the API using tools like REST Client in Visual Studio Code.
This project is licensed under the MIT License. See the LICENSE file for details.