- Clone the repository:
git clone git@github.com:mauriciolopes/desafio-b2w - Go to
cmd/planet-apifolder and run:go install - Run:
$GOPATH/bin/planet-api
- Docker
- Docker Compose
- Internet connection (to extract informations of swapi.dev)
- Clone the repository:
git clone git@github.com:mauriciolopes/desafio-b2w - Inside the root project folder:
docker-compose up --build
DB_URI: configure database server (defaultmongodb://localhost:27017)DB_NAME: configure database name (defaultstarwars)HTTP_ADDR: configure http server host and port (default:8080)
These configurations have priority over environment variables.
-db-uri: configure database server (defaultmongodb://localhost:27017)-db-name: configure database name (defaultstarwars)-http-addr: configure http server host and port (default:8080)
DB_URI=mongodb://localhost:27017 DB_NAME=starwars planet-apiHTTP_ADDR=localhost:8088 planet-api -db-uri=mongodb://localhost:27017The content type of requests and responses is application/json.
POST /planets
Request
| Field | Type | Description | Rules |
|---|---|---|---|
| name | string | Name of the new planet | required, unique |
| climate | string | Climate of the new planet | required |
| terrain | string | Terrain of the new planet | required |
Response example
HTTP Status: 201 Created
{
"id": "5ed656285d9f32274f847473",
"name": "Hoth",
"climate": "frozen",
"terrain": "tundra, ice caves, mountain ranges",
"filmAppearances": 1
}GET /planets
Response example
HTTP Status: 200 OK
[
{
"id": "5ed656285d9f32274f847473",
"name": "Hoth",
"climate": "frozen",
"terrain": "tundra, ice caves, mountain ranges",
"filmAppearances": 1
},
{
"id": "5ed659005d9f32274f847474",
"name": "Naboo",
"climate": "temperate",
"terrain": "grassy hills, swamps, forests, moutains",
"filmAppearances": 4
},
{
"id": "5ed659415d9f32274f847475",
"name": "Kamino",
"climate": "temperate",
"terrain": "ocean",
"filmAppearances": 1
}
]GET /planets/:id
Response example
{
"id": "5ed659005d9f32274f847474",
"name": "Naboo",
"climate": "temperate",
"terrain": "grassy hills, swamps, forests, moutains",
"filmAppearances": 4
}GET /planets?name=:name
Response example
{
"id": "5ed659005d9f32274f847474",
"name": "Naboo",
"climate": "temperate",
"terrain": "grassy hills, swamps, forests, moutains",
"filmAppearances": 4
}DELETE /planets/:id
Response example
HTTP Status: 200 OK