Giter VIP home page Giter VIP logo

golang-mongo-api's Introduction

Golang API

Rest API with Golang and MongoDB

At the moment need to have installed Go and MongoDB to use this code

See the section Running the app with docker-compose

This API try to get the best price (purchase and sale) of currencies from multiple Operators

To start:

  1. Clone this repo using git clone https://github.com/wchopite/golang-mongo-api.git
  2. Rename the file .env.example to .env and setup the environment vars
  3. Run the application with go run main.go
  4. Access http://localhost:1337/api/currency

Each request to the API must include the following headers:

Content-Type: "application/json"

Things to do after configuration and running

  1. Create a currency price using the POST /api/currency endpoint and the next payload (for example):
{
    "coin" : "USD",
    "purchase_value" : 60.58,
    "sale_value" : 58.59,
    "operator" : "Santander"
}
  1. Then, you can use the other endpoint GET /api/currency. This endpoint return (for example):
[
    {
        "Coin": "EUR",
        "Purchase_value": 65,
        "Sale_value": 69,
        "Operator": "Banco Nacion"
    },
    {
        "Coin": "USD",
        "Purchase_value": 61.5,
        "Sale_value": 57.5,
        "Operator": "Banco Nacion"
    }
]

You can get the best value only for one currency using in the query params the var key (this var represent the currency). For example:

GET /api/currency?key=USD

The return value:

[
    {
        "Coin": "USD",
        "Purchase_value": 61.5,
        "Sale_value": 57.5,
        "Operator": "Banco Nacion"
    }
]

Running the app with docker-compose

Working in Progress

  1. Install Docker: https://docs.docker.com/compose/install/
  2. Install Docker Compose: https://docs.docker.com/compose/install/

Once you have installed them, in the root folder you need to run docker-compose up. This command generate the containers with the go app and mongo database. Then you can test it using a Restful client, like Postman

Tech Stack

  1. Golang: https://golang.org/
  2. Gorilla Mux: https://github.com/gorilla/mux
  3. MongoDb: https://docs.mongodb.com/manual/
  4. MongoDb Driver for go: https://docs.mongodb.com/ecosystem/drivers/go/
  5. Godotenv: https://github.com/joho/godotenv

To Do

  1. Add unit and integration test
  2. Add input validation on endpoints
  3. Add coverage
  4. Add a cache layer with redis for example
  5. A better code organization. Divide in a better way the multiple layers
  6. Add files configuration to CI/CD (codeship, google cloud build, etc)
  7. Keep learning about Go, best practices, standards
  8. Patterns, patterns, patterns...

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.