Skip to content

jjmrocha/oblivion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Oblivion

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.

Features

  • 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.

Project Structure

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.

REST API Endpoints

Buckets

List Buckets

GET /v1/buckets

Response:

[
  "bucket1",
  "bucket2"
]

Create Bucket

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 Bucket

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 Bucket

DELETE /v1/buckets/{bucket}

Response: 204 No Content


Keys

Get Key

GET /v1/buckets/{bucket}/keys/{key}

Response:

{
  "id": "id1",
  "first_name": "John",
  "last_name": "Doe"
}

Set Key

PUT /v1/buckets/{bucket}/keys/{key}

Request Body:

{
  "id": "id1",
  "first_name": "John",
  "last_name": "Doe"
}

Response: 204 No Content

Delete Key

DELETE /v1/buckets/{bucket}/keys/{key}

Response: 204 No Content

Find Keys

GET /v1/buckets/{bucket}/keys?field=value

Response:

[
  "key1",
  "key2"
]

Running the Project

  1. Install Go (version 1.22 or later).
  2. Clone the repository:
    git clone https://github.com/jjmrocha/oblivion.git
    cd oblivion
  3. Run the application:
    go run main.go
  4. The server will start on http://localhost:9090.

Testing the API

You can use the provided test.http file to test the API using tools like REST Client in Visual Studio Code.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Oblivion is a Go-based playground project that implements a REST API for managing buckets and their associated keys and values

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages