Skip to content

thslopes/escambo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Escambo POC

REST API with Go-Chi and MongoDB Driver

This is a POC and it's not ready for production.

Diff sample

{
    "id": "2",
    "user_id": 10,
    "title": "article 2",
    "slug": "article-23",
    "versions": [
        {
            "article": {
                "id": "2",
                "user_id": 10,
                "title": "article 2",
                "slug": "article-21",
                "versions": null
            },
            "changes": "  db.Article{\n  \tID:       \"2\",\n  \tUserID:   10,\n  \tTitle:    \"article 2\",\n- \tSlug:     \"article-21\",\n+ \tSlug:     \"article-22\",\n  \tVersions: nil,\n  }\n",
            "user_id": 10
        },
        {
            "article": {
                "id": "2",
                "user_id": 10,
                "title": "article 2",
                "slug": "article-22",
                "versions": null
            },
            "changes": "  db.Article{\n  \tID:       \"2\",\n  \tUserID:   10,\n  \tTitle:    \"article 2\",\n- \tSlug:     \"article-22\",\n+ \tSlug:     \"article-23\",\n  \tVersions: nil,\n  }\n",
            "user_id": 10
        }
    ],
    "elapsed": 10
}

MongoDB Docker

docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=test -e MONGO_INITDB_ROOT_PASSWORD=123 -d mongo:latest

Load DB

go run cmd/mock/main.go

Running the app

go run cmd/main.go

Make

make mongo-docker
make load-db
make run

Endpoints

/articles

GET

curl --location --request GET 'http://localhost:3333/articles'

POST

curl "http://localhost:3333/articles" \
-d '
{
    "title": "Article 1",
    "slug": "article-1",
    "user_id": 10
}'

/articles/{id}

GET

curl --location --request GET 'http://localhost:3333/articles/2'

PUT

curl --location --request PUT 'http://localhost:3333/articles/2' \
--header 'Content-Type: application/json' \
--data-raw '{
    "title": "Article 2",
    "slug": "article-2",
    "user_id": 10
}'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors