Giter Club home page Giter Club logo

gocrud's Introduction

gocrud

REUSE status

Simple CRUD application that exposes an HTTP REST API to store data inside a MongoDB database.

Usage

Configuration

gocrud is configured via command-line flags or environment variables.

Flag Environment variable Default Description
--bind-address GOCRUD_BIND_ADDRESS 0.0.0.0:8080 Address to serve API on
--mongo-uri GOCRUD_MONGO_URI mongodb://localhost:27017 MongoDB URI to use
--mongo-db GOCRUD_MONGO_DB gocrud MongoDB database to use

MongoDB authentication

Authentication can be provided via the MongoDB URI. Example:

GOCRUD_MONGO_URI=mongodb://admin:password@localhost:27017

API

By default, gocrud exposes the following endpoints on port 8080:

Create pet

Creates a new pet, and returns the ID of the pet created.

POST /v1/pet
Accept: application/json
Content-Type: application/json

{
  "name": "string",
  "species": "string",
  "breed": "string"
}
Responses (click to expand)
  • Object successfully created
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "id": "string"
}
  • Invalid request body
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8

{
  "error": "string"
}
  • Failed to create object in database
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8

{
  "error": "string"
}

Get pet

Retrieves an existing pet.

GET /v1/pet/:id
Accept: application/json

Parameters:

  • :id (path): ID of the pet object, formatted as a 24-character long hexadecimal number.
Responses (click to expand)
  • Object successfully retrieved.
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "id": "string",
  "name": "Grande Hazelnut Mc.Muffin",
  "species": "dog",
  "breed": "Dobermann"
}
  • Invalid :id parameter format.
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8

{
  "error": "string"
}
  • No pet was found with the ID of :id
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8

{
  "error": "string"
}
  • Failed to retrieve object from database.
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8

{
  "error": "string"
}

Development

Prerequisites

  • Go 1.20 (or higher)
  • A way to run MongoDB locally, e.g via a container using Podman

Running locally

  1. Start up a local MongoDB instance, for example via Podman:

    podman run --rm -it -p 27017:27017 mongo
  2. Run gocrud locally, e.g:

    go run .
  3. To test out the webhooks, you can make use of our example webhook like so:

    $ curl localhost:8080/v1/pet --json @examples/pet.json
    {"id":"63d00f3a87cb268ed07657e6"}
    
    $ curl localhost:8080/v1/pet/63d00f3a87cb268ed07657e6
    {"id":"63d00f3a87cb268ed07657e6","name":"Grande Hazelnut Mc.Muffin","species":"dog","breed":"Dobermann"}

License

This repository complies with the REUSE recommendations.

Different licenses are used for different files. In general:

Please see each file's header or accompanied .license file for specifics.

gocrud's People

Contributors

applejag avatar dependabot[bot] avatar

Watchers

Piotr Roszatycki avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.