Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gugutz/stairs-backend-challenge

Backend Challenge for Stairs Studio, written in Go.
https://github.com/gugutz/stairs-backend-challenge

Last synced: 27 days ago
JSON representation

Backend Challenge for Stairs Studio, written in Go.

Awesome Lists containing this project

README

        

# Stairs Backend Challenge

This is my solution for the Stairs Backend Challenge.

Written in Go, using MongoDB and Go Modules mode.

## Install and Run

This API uses [Go](http://golang.org) and [MongoDB](https://mongodb.com).

The MongoDB is instanced using [Docker Compose](https://github.com/docker/compose).

### Setting up the Database
The MongoDB is instanced using docker-compose.

Navigate to the API folder and raise the database with:
```sh
$ docker-compose-up
```

### Creating the database and a collection

Once MongoDB is up, you must create a database and a collection.
This setup also raises a **Mongo Express** instance to make this easier.

The address to the Mongo Express configuration page is: **`localhost:8081`**

### Updating the configuration file

After creating the database and the collection, open the `config.toml` file in the root folder and update the fields to match the name of the database and the collection you created.

### Run the API
After raising the database instance, run the API:
```sh
$ go run main.go
```

## API Description

This is a REST API made with Go that exposes 5 endpoints:






POST


/wines


Get all wines




*Parameters:*
```
No parameters
```




GET


/wines


Get all wines



*Parameters:*

```
No parameters
```




POST


/wines/new


Add wines



*Parameters:*

name string

harvestinteger

countrystring

amountint

descriptionstring

*Usage Example:*

```json
{
"name": "Petrus",
"harvest": 1984,
"country": "France",
"ammount": 0,
"description": "This wine comes from the regions of..."
}
```


NOTE: MongoDB adds the ObjectID automatically if its not specified




PUT


/wines/{id}


Update a wine



*Parameters:*

idint

wineStruct

*Usage Example:*

```json
{
"id": "5d881cf1d663f81498131a81",
"wine": {
"name": "New Name",
"harvest": 2005,
"country": "New Country",
"ammount": 0,
"description": "New description for the wine..."
}
}
```





DELETE


/wines/{id}


Deletes a wine



*Parameters:*

idint