Giter Club home page Giter Club logo

autopilot-proxy's Introduction

Autopilot API caching middleware server

Implement Golang caching middleware server for Autopilot API /contact method (you can create a free trial account and read about Autopilot API on https://autopilot.docs.apiary.io/#introduction/getting-help):

  • Create GET / POST / PUT /contact endpoint
    • Note: PUT in not supported by API Docs, but POST support idempotency, and act like PUT
      # PUT response example at API
      {
          "code": "MethodNotAllowedError",
          "message": "PUT is not allowed"
      }
      
  • Retrieve a requested contact from redis, if it is not present retrieve it from Autopilot API and store in redis
  • Create / Update a contact and invalidate redis cache after POST / PUT requests
  • Cover the necessary methods with unit tests
  • Write README file with instructions how to run and test it

Run Reverse Proxy

Before running service please make that Environment Variables are set correctly and point correct services, by default it set to:

export AUTOPILOT_API="https://private-1f378a-autopilot.apiary-proxy.com"
export REDIS_HOST="localhost:6379"

Please run server.go file and listen Reverse Proxy on port 8080.

$ go get -v
$ go run ./

Post Contact

request example

curl --location --request POST 'http://0.0.0.0:8080/v1/contact' \
--header 'autopilotapikey: xxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "contact": {
    "FirstName": "Bob",
    "LastName": "Goodman",
    "Email": "[email protected]",
    "custom": {
      "string--Test--Field": "This is a test"
    }
  }
}'

expected response

{
    "contact_id": "person_BEDEF3B9-8B84-4F5F-AA58-22D025DDA683"
}

Get Contact

request example

curl --location --request GET 'http://0.0.0.0:8080/v1/contact/person_BEDEF3B9-8B84-4F5F-AA58-22D025DDA683' \
--header 'autopilotapikey: xxxxxxxxxxxxxxxxxxxxxxx'

expected response

{
    "Email": "[email protected]",
    "created_at": "2021-10-31T04:21:50.000Z",
    "updated_at": "2021-10-31T04:21:50.000Z",
    "api_originated": true,
    "custom_fields": [
        {
            "kind": "Test Field",
            "value": "This is a test",
            "fieldType": "string",
            "deleted": false
        }
    ],
    "Name": "Bob Goodman",
    "LastName": "Goodman",
    "FirstName": "Bob",
    "contact_id": "person_BEDEF3B9-8B84-4F5F-AA58-22D025DDA683"
}

Test Cover

to run tests

 go test -v -cover ./...

Expected output

=== RUN   TestGetContact

  Test GET Contact ✔✔✔✔✔
    Test cache is set ✔✔


7 total assertions

--- PASS: TestGetContact (0.10s)
=== RUN   TestPostContact

  Test POST Contact ✔✔✔✔✔✔
    Test POST invalidate cache ✔


14 total assertions

--- PASS: TestPostContact (0.11s)
PASS
coverage: 70.4% of statements
ok      github.com/xsoroton/autopilot-proxy/handlers    0.218s  coverage: 70.4% of statements
=== RUN   TestStoreMem

  Test Store Mem ✔✔✔✔✔✔


6 total assertions

--- PASS: TestStoreMem (0.00s)
PASS
coverage: 65.2% of statements
ok      github.com/xsoroton/autopilot-proxy/store       (cached)        coverage: 65.2% of statements

autopilot-proxy's People

Contributors

xsoroton avatar

Watchers

James Cloos avatar  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.