This project requires JDK 1.8 or later. Run the project by executing the following command. Replace CLIENT_SECRET with the actual client secret.
mvn spring-boot:run -Dspring-boot.run.arguments=--fitpay.api.secret=CLIENT_SECRET
Note: The access token is retrieved automatically and does not need to be provided. However, it does not get renewed when expired.
curl http://localhost:8080/compositeUsers/{userId}
{
"userId": "123",
"devices": [
{
"state": "INITIALIZED",
"deviceIdentifier": "456"
}
],
"creditCards": []
}In order to increase the efficiency of a client using the FitPay API, we need a new composite API resource created that will decrease the number of network calls being made.
- Technology choice is whatever platform you're comfortable in
- If you chose a java based solution, a very basic spring-boot application is included.
- API credentials and/or bearer tokens can be hard coded with values obtained out-of-band
- You're familiar with curl for testing Restful APIs
- Your solution can ideally be launched with a single command, if not instructions MUST be provided so we can test your new API
- Example
mvn spring-boot:run
- Example
API clients typically need to make three separate network calls to obtain all the information necessary for a robust end consumer experience:
GET https://api.qa.fitpay.ninja/users/:userId
GET https://api.qa.fitpay.ninja/users/:userId/devices
GET https://api.qa.fitpay.ninja/users/:userId/creditCards
We need a new API resource that composes these 3 separate calls into a single JSON structure so our API clients don't need to make 3 network calls anymore:
GET http://localhost:8080/compositeUsers/:userId
- Given the
userIdas part of the URL path, retrieve the underlying API resources from the FitPay API - The
Content-Typereturned MUST beapplication/json - The JSON returned MUST at least include the following elements
userIdcreditCardIdstatefor both devices and creditCardsdeviceId
- The
devicesandcreditCardsMUST support lists of 0-n values - The API SHOULD support two optional filters
creditCardState- Filter credit cards bystateif query parameter specifieddeviceState- Filter device bystateif query parameter is specified
Example Requests:
GET http://localhost:8080/compositeUsers/:userId?creditCardState=ACTIVE
GET http://localhost:8080/compositeUsers/:userId?deviceState=INITIALIZED
GET http://localhost:8080/compositeUsers/:userId?creditCardState=ERROR&deviceState=FAILED_INITILIZATION
- The endpoint will present self-signed SSL certificates, you'll need to either disable SSL validation all together or download and import the certificate into your trusted store.
- You'll be using our development/testing environment, which at times can be unstable. You can validate the health of the environment here.
- Review the JSON returned by the API to see if there are hints and useful things that can assist in making further API invocations
Authentication is achieved through an oauth2 bearer token, obtained through a client_credentials grant utilizing the credentials issued to you from FitPay:
curl -s --insecure -u CLIENT_ID:CLIENT_SECRET https://auth.qa.fitpay.ninja/oauth/token?grant_type=client_credentials
Using the access_token retrieved above, obtaining a collection of users:
curl -s --insecure -H "Authorization: Bearer TOKEN" https://api.qa.fitpay.ninja/users?limit=10
Using the access_token retrieved above, obtaining an individual user:
curl -s --insecure -H "Authorization: Bearer TOKEN" https://api.qa.fitpay.ninja/users/:userId
Using the access_token retrieved above, obtaining a collection of a user's devices:
curl -s --insecure -H "Authorization: Bearer TOKEN" https://api.qa.fitpay.ninja/users/:userId/devices
Using the access_token retrieved above, obtaining a collection of a users's credit cards:
curl -s --insecure -H "Authorization: Bearer TOKEN" https://api.qa.fitpay.ninja/users/:userId/creditCards
More details API documentation can be found here.