Giter VIP home page Giter VIP logo

go-erply-proxy's Introduction

go-erply-proxy

This repository contains proposed solution for a task received from Erply.

Task

Read/Write customer data over API

The application uses github.com/erply/api-go-wrapper to read and write brands.

Simple authentication of requests (token)

It is needed to add http header authorization with the value.

# Authorization: <sessionKey>:<client code>

curl -X 'GET' \
  'http://localhost:8081/v1/brand?skip=0&take=28' \
  -H 'accept: application/json' \
  -H 'Authorization: f3d39852878ffab3836d6e0da80c26629926eeab3e4:000000'

Use database for local storage (cache)

This project utilizes Redis as a local storage solution. Data is stored using composite keys, which consist of the URI path and URI parameters. For example, the URI path could be /v1/brand, and the associated parameters may include skip=0_take=25.

During a GET request, the system first checks the cache for the requested data. If no results are found in the cache, the data is retrieved from the Erply API and directly served to the API consumer. Simultaneously, the response is saved to the cache in the background.

When a new record is added for the /v1/brand URI, the cache is cleared for the brands category key. This ensures that only the relevant brand data is removed from the cache.

To ensure data freshness, the entire cache is flushed every 30 seconds, keeping the data up to date.

This caching mechanism optimizes data retrieval by minimizing reliance on the Erply API and significantly reducing response times for subsequent requests.

Includes simple documentation (Readme.md)

Check.

Includes swagger or apidoc for functions

SwaggerUI is served from the server root. Additionally, a Postman collection can be found in the ./api directory.

Includes Unit tests

Unit tests have been implemented and are passing for successful create and read list requests.

Run

docker compose build

docker compose up               # Run all, press Ctrl+C to quit

docker compose down             # Tear down network

Open http://localhost:8081/ to explore the aPI using the swagger UI.

Develop

docker compose -f docker-compose-redis.yaml up  # Run Redis

go get -d -v ./... && go install -v ./...       # Prep Go

go test -v ./...                                # Run unit tests

go run ./main.go                                # Run Go App

Known issues

Pagination doesn't seem to work correctly. Attempts were made with recordsOnPage and pageNo, but without success. Further investigation is required.

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.