Git Product home page Git Product logo

handle-with-api-external's Introduction

Writing an External Integration

Integrating with external partners via APIs is the rule nowadays. Commonly they are modern and well design... but sometimes they are not!

Your task is to write a layer on top of a (fictional) poorly designed API, providing a better experience to consume the resource. It's expected:

  • a client that consumes two endpoints of the old api
  • a webserver, exposing only one endpoint: POST /account

This document outlines the input your program will receive and the expected output. It also includes a little background information on the problem domain.

Creating an account

The external API is not available yet. No worries, we have the documentation!

To create a new account, the external API exposes POST http://api.partner.com/request-account and expects data in the following format (this is a valid input):

{
  "name": "John Lennon",
  "email": "[email protected]",
  "date_of_birth": "1980-12-08",
  "country" : {
    "code": "UK"
  }
}

The country code is an alpha3.

Note that there are no validations on their side. If the payload is somehow different from the example above, their api can behave in unexpected ways.

If it's a successful request, it will respond with 200:

{
  "status": 0,
  "request_id": "{uuid}",
  "accepted_at": "2021-11-05T11:03:42Z"
}

However, if something goes wrong, it still responds with 200, but the body is:

{
  "status": -1, 
  "error_message": "Something is wrong"
}

In this case, you should retry the request once before assuming it's a failure.

Checking if the account is ready

Unfortunately, the external partner has never heard of webhooks. They expose GET http://api.partner.com/status/{request_id} for us to check the account status. The possible responses are:

{
  "request_id": "{request_id}",
  "status": {
    "code": 1,
    "description": "Processing"
  }
}
{
  "request_id": "{request_id}",
  "status": {
    "code": 2,
    "description": "Ready"
  }
}
{
  "request_id": "{request_id}",
  "status": {
    "code": 3,
    "description": "Cancelled"
  }
}

They can take up to 10 seconds to verify an account and respond with Ready or Cancelled. Your task here is:

  • to check the account status, looking for Ready or Cancelled
  • to check the status once every second, up to 4 seconds

If the account is ready or cancelled, the code stops checking. After the fourth attempt, if the account is not complete, the code stops checking as well. In this case, the status of the account should be considered In Progress.

The output

A successful request to your api should return one of the following three responses:

{ "status": "Ready" }
{ "status": "Cancelled" }
{ "status": "In Progress" }

Your solution

Submitting

Your code should be submitted in a tarball that contains a ./bin/server executable script.

This command will be expected to speed up the webserver and expose the http://localhost:8080/account endpoint.

Your program will be expected to run on OSX or Linux. If your program requires special pre-requisites (if it needs the Go compiler for example) please include it in your submission's README.

Tips

The problem is not specific about some requirements on purpose, we want to see how you will deal with them.

Please write your solution in a language you feel confident in. Your program should both produce the expected output and be well written. Java is allowed; Spring is not.

***** Solution applied ******

My solution was to create a retry system where I can control de timeouts in communication between services. The system can be configured with parameters.

  • Jersey
  • JAX-RS
  • Lombok

0 - it is necessary to have maven on the machine

1 - extract to any folder

2 - it will create the application folder

3 - cd application

4 - mvn clean compile

5 - mvn exec:java

6 - testing in postman:

{
  "name": "John Lennon",
  "email": "[email protected]",
  "date_of_birth": "1980-12-08",
  "country" : {
    "code": "UK"
  }
}

handle-with-api-external's People

Contributors

robinsonvs avatar

Watchers

 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.