Coder Social home page Coder Social logo

wex-tag's Introduction

opinionated-go-api

A toy application for a random Job Application. See REQUIREMENTS.md. Contains a very opinionated approach to API development in Golang using oapi-codegen for types generation to entgo for ORM framework.

The service exposes APIs to Store a Purchase Transaction and Retrieve a Purchase Transaction in a Specified Countyr's Currency.

API: POST {BASE_URL}/purchase

Request Body: {
    "description": "new description",
    "amount": "100.1223"
}

Response: {
    "amountInUSD": "100.12",
    "date": "2023-12-01T10:58:37.050074Z",
    "description": "new description",
    "id": "c4c1666f-2eda-49c7-99b8-635223f1330a"
}
API: GET {BASE_URL}/purchase/ae90db91-d278-4941-b2b0-92e3b6f666e2?country="United Kingdom"&currency=Pound

Response: {
    "convertedDetails": {
        "amount": "8.26",
        "country": "'United Kingdom",
        "currency": "Pound",
        "exchangeRateDate": "2023-09-30",
        "exchangeRateUsed": "0.816"
    },
    "transactionDetails": {
        "amountInUSD": "10.13",
        "date": "2023-12-01T09:28:12.573092Z",
        "description": "new description",
        "id": "ae90db91-d278-4941-b2b0-92e3b6f666e2"
    }
}

Technical Overview

  1. API Specification are described in 'openapi.yaml' file which follows OpenAPI 3.1 standard.
  2. API types are autogenerated from 'openapi.yaml' file using oapi-codegen pkg.
  3. HTTP service is built using Go Chi Router.
  4. File 'pkg/api/transaction.go' contains Handler code for our two APIs
  5. Package 'pkg/api/service' contains business logic required for our two APIs
  6. Postgres DB is used as persistence layer and is dockerized in the codebase.
  7. ent.go is used as ORM framework

Running the application

  1. copy .env.example and create .env file with given environment variables.
  2. Run "docker compose up" to initiate a postgres instance.
  3. Run "make run" command to run a go server
  4. Make curl request for new purchase transaction using "make post"
  5. Get the transaction Id from output of POST request and use that to make GET request!

wex-tag's People

Contributors

eddie023 avatar

Watchers

 avatar

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.