Skip to content

About

A simple REST API service

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

A Golang-based REST API service

Design

The application was implemented according to the provided specifications. The main components are:

  • Programming language: Go, selected for its strong typing and concurrency model
  • Storage: SQLite, selected for its simplicity and performance
  • Web server: Gin, selected for its lightweight HTTP routing and middleware support
  • Logging: Zerolog, selected for its low overhead and efficient structured logging (useful for log analisys tools like Datadog)
  • Bucket object deduplication: SHA-256, selected for its good balance of computational efficiency and collision resistance

Endpoints

  • GET /objects/{bucket}/{objectID}: retrieve an object by bucket ID and object ID
  • PUT /objects/{bucket}/{objectID}: create an object in the specified bucket using the provided object ID, needs also content to be passed in the request JSON body
  • DELETE /objects/{bucket}/{objectID}: delete an object by bucket ID and object ID

Examples

  • PUT /objects/test-bucket/test-id Body:
{
    "content":"some-content"
}

Response:

{
    "bucket": "test-bucket",
    "objectID": "test-id",
    "message": "Object stored successfully"
}
  • GET /objects/test-bucket/test-id

Response:

{
    "bucket": "test-bucket",
    "objectID": "test-id",
    "message": "Object retrieved successfully",
    "content": "some-content"
}
  • DELETE /objects/test-bucket/test-id

Response:

{
    "bucket": "test-bucket",
    "objectID": "test-id",
    "message": "Object deleted successfully"
}

Environment variables

  • LISTENING_ADDRESS: IP address or hostname on which the web server listens, defaults to 0.0.0.0
  • HTTP_PORT: TCP port on which the web server listens, defaults to 8080
  • GIN_MODE: configures wheter app should run in debug or production mode, defaults to release

Run tests

To run the integration test suite, execute make test.

NOTE: due to the limited scope of the task, only integration tests were implemented.

Deploy

To deploy locally, run make all or make all-docker. To deploy to production, apply the Kubernetes manifests in the deploy directory.

Production Notes

  • Enable HA
  • Migrate to an external PostgreSQL instance as the primary datastore
  • Introduce stateless authentication (e.g. JWT) and application security controls (e.g. CORS, CSP, etc.)
  • Introduce a caching layer (e.g. Redis)
  • Kustomize or add Helm Chart for Kubernetes deployment
  • Add a /metrics endpoint
  • Add Swagger and OpenAPI documentation
  • Add linting and hot reloading (for development purposes)
  • Move to a fully RESTful resource structure /buckets/{bucketID}/objects/{objectID}:
    • GET object on the /buckets/{bucketID}/objects/{objectID} endpoint
    • POST new objects on the /buckets/{bucketID}/objects endpoint (the object ID must be assigned by the backend)
    • PUT existing objects (override) on the /buckets/{bucketID}/objects/{objectID} (or just use PATCH)
    • DELETE object on the /buckets/{bucketID}/objects/{objectID} endpoint

AI Use

During development, AI assistance was used exclusively to generate code boilerplate via GitHub Copilot. All generated boilerplate was manually reviewed, validated, and refined before integration.

About

A simple REST API service

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages