Racer API | AnyPoint Speedway
Anypoint Speedway (The MuleSoft API Race Where Acceleration Meets Integration) is launched with Season 3. So, Muleys all around the world get ready to RACE. Once we scroll through the instructions, we see a need for Racer API, which will be used to compete in the race. Currently, Racer API can be built in any of the platforms, all it needs is a public endpoint with implementation as per specification.
But, we are the MuleSoft developers, so let's build the API in MuleSoft. If you are a beginner or professional Muley, this article will help you implement the Racer API and participate in the race. Let's fasten up the seatbelt and start developing the Racer API.
Anypoint Speedway has made our lives easier by providing the readily available specification file.
Pre-requisite
racerId
To enter the race, the RACER is required to register for the race and get a racerId.
1. Go to Anypoint Race API, and Click on Request Access. Log in with AnyPoint Platform credentials.
2. Fill in the details as shown below. If an application is not seen, create a new application by providing the name. Click on Request access. For initial access use the Basic SLA tier.
3. This will generate/show the client-id and client-secret which will be used to authenticate the requests to Anypoint Race API.
4. Go to POST /register resource. Follow the instructions to generate a racerId. You may use the portal to send a request or any rest client(e.g. Postman) to send a request and get a racerId for your racer.
"displayName": "Sylvester the Cat",
"email": "sylvester@wb.com",
"racerId": "racer-id-value",
"clientId": "clientId"
}
Highlighted racerId will be used in building the RACER API.
RACER API
1. Download the RAML specification file from the Anypoint Speedway portal. Click on Download and then as RAML. RAML file will be downloaded to the system.
3. Enter the project/racer name, specify the downloaded file's location, and click on finish.
A project will be created with scaffold flows as per the specification file.Let's build the flows for Tier I. For Tier I, the token is required to be used in further requests. For this, an object store can be used.
4. Add the ObjectStore module in Mule Palette. Click on Global Elements, then click on Create.
5. Select ObjectStore Config under Connector configurations. Click on OK.
6. Check the Connection checkbox and click on OK. A connection configuration will be created.
7. Click on Create again to add another global configuration for ObjectStore. Select ObjectStore under Component Configuration and click OK.
8. Specify the connection reference for ObjectStore created in the previous step. Click OK.
9. Click on Message flow to go back to flows. Go to "post:\races:application\json:racer-api-config" flow configuration.
10. Drag and drop the Store connector from the Mule Palette. Specify the details as mentioned in the below screenshot.
11. Drag a set variable and set the name as raceId and value as uuid(). Configuration should look like as below.
12. Drag a transform message and set the values as shown below. Replace the "race-id-value" with the value, received from the Anypoint Race API POST /register.
13. The overall flow will look like below.
To pass Tier I, at least 1 lap needs to be completed. Let's update the "post:\races\(id)\laps:text\plain:racer-api-config"
14. Drag the Retrieve connector under ObjectStore from Mule Palette, and place it after the transform message. Specify the values as shown below. Token value will be retrieved from the Object store.
15. Drag the transform connector. And update the transform connector with values as below.
The flow will look as below.
16. Save and export the API. Right-click racer project -> Export. Under Mule, select Anypoint Studio Project to Mule deployable archive. Click Next.
17. Specify the export jar location and click on Finish.
Now the RACER API is ready to race for Tier I. Let's deploy to the AnyPoint platform and start the race.
18. Go to the AnyPoint platform, then to Runtime Manager, select the environment where you want to deploy. Click on Deploy application.
19. Specify the application name, and upload the jar file created in the previous step. Tick the checkbox to use ObjectStore V2 and click on Deploy.
After deployment, a public URL similar to "https://deciphermiddleware-racer-syivqn.5sc6y6-4.usa-e2.cloudhub.io" will be generated. This will be used to enter the race and compete with other racers.
Enter the Race
1. To make an entry in the race, trigger a request to Anypoint Race API POST /racers/{racerId}/entry.
2. Provide the public endpoint along with /api "API kit is used /api is added before every resource". Any REST client can be used to trigger the request by providing details as mentioned in the API documentation.
The RACER has started RACING. Go to the Leaderboard and see your racer name coming up.Oh wait there are a total of 5 Tiers! So, wear your developer hats and enhance the Rookie Racer to level up to Tier V.
Comments
Post a Comment