Simple CRUD application that exposes an HTTP REST API to store data inside a MongoDB database.
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 |
Authentication can be provided via the MongoDB URI. Example:
GOCRUD_MONGO_URI=mongodb://admin:password@localhost:27017
By default, gocrud exposes the following endpoints on port 8080:
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" }
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" }
- Go 1.20 (or higher)
- A way to run MongoDB locally, e.g via a container using Podman
-
Start up a local MongoDB instance, for example via Podman:
podman run --rm -it -p 27017:27017 mongo
-
Run gocrud locally, e.g:
go run .
-
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"}
This repository complies with the REUSE recommendations.
Different licenses are used for different files. In general:
- Go code is licensed under GNU General Public License v3.0 or later (LICENSES/GPL-3.0-or-later.txt).
- Documentation licensed under Creative Commons Attribution 4.0 International (LICENSES/CC-BY-4.0.txt).
- Miscellaneous files, e.g
.gitignore
, are licensed under CC0 1.0 Universal (LICENSES/CC0-1.0.txt).
Please see each file's header or accompanied .license
file for specifics.