Today we will build a dummy API giving use the details of vehicles for sale in the open market, and the details of the seller. We will provide two API endpoints:

  • Get all vehicles for sale
  • Get all vehicles for sale from a specified manufacturer

For each vehicle found, our API will return the following properties:

  • Vehicle Registration Number
  • Manufacturer
  • Model
  • Registration Date
  • Mileage
  • Colour
  • Price
  • Seller name
  • Seller contact number

Create an account at Mockaroo – it’s free and a really useful services for developers to create dummy datasets, APIs and databases. Add the following fields:

Field NameTypeOptions
registrationCharacter Sequence^^## ^^^ (two letters, two numbers, space, three letters)
manufacturerCar Make
modelCar Model
registration_dateDatetimeset desired min and max dates
mileageCharacter Sequence##### (five random digits)
colourColor
priceMoneyset desired min and max price range
first_nameFirst Name
last_nameLast Name
contact_numberPhoneset desired phone number format.

Click the Save As… button and give the schema the name MarketVehicles and click Save.

Next, click on Schemas from the top ribbon. From the list of available schemas, select MarketVehicles.

From the schema screen, select Generate Data.

Click on Datasets from the top ribbon. From the list of available datasets, select MarketVehicles.

Now that we have created a dummy dataset, we want to create API endpoints to fetch this data. Click on APIs from the top ribbon, then click the Create a new Mock API button.

Complete the screen as follows then click the Create mock API button.

  • Route – GET /market_vehicles
  • Handler Script – from_dataset(“MarketVehicles”, as_json: true)

And that’s our first API endpoint created! The Mock API screen will provide a URL where you can test the endpoint. The URL is the of the format:

https://my.api.mockaroo.com/market_vehicles/?key=XXX

The key parameter here is used by Mockaroo to authenticate the request – if it is not supplied, then our API will return a HTTP code of 401 (Unauthorized) and supply an error message. The value of key here is tied to your user account. Many third party APIs use API_KEY authentication like this. All being well, a successful request to our endpoint should look something like this:

Ideally, we’d like to supply some filter parameters to our API – let’s create another endpoint to do this.

Pages: 1 2 3 4

One response to “Working with APIs Part 1: Creating a test API”

  1. Working with APIs Part 2: Creating a Custom Connector – Power Platform Pete Avatar

    […] our last post we created a test API using Mockaroo and then integrated it into our LaRusso Autos solution with a […]

    Like

Leave a comment