Foobar.REST

A handy API for common utils and mock data

As a Software Engineer, I commonly run into similar problems over and over again. Looking up the same information, or trying to get example data or endpoints for testing and developing can be monotonous and time wasting. So I decided to make my own personal API to help solve some of these commmon issues.

How I use these - Espanso

I use Espanso text expander to call these endpoints on the fly. Here is an Espanso config file example of how I can generate a UUID while typing:

    - trigger: ":uuid"
      replace: "{{output}}"
      vars:
          - name: output
            type: shell
            params:
                cmd: "curl -L foobar.rest/utils/uuid"
                shell: cmd

When I am trying to create mock data that has a UUID, I can simply type :uuid to generate one on the fly. This helps prevent problems when using strings like test123 for a field that needs to be a UUID, such as not accounting for correct length, or satisfying a regex match.

Other utilities can be used in a similar manner.

API Collection

I have a Thunder Client collection available here:

Thunder Client collection

Features

Utilities

Sleep Timer

If you need to simulate a long running API call, to test a timeout for example, you can use the following endpoint with number of seconds as a path parameter:

https://foobar.rest/utils/sleep/3

UUID/UUIDv7

The most common utility I use is generating UUID’s.

https://foobar.rest/utils/uuid
https://foobar.rest/utils/uuidv7

More info on UUIDv7: https://uuid7.com/

Random String

If you just need random chars:

https://foobar.rest/utils/random/12

HTTP Status Codes

You can use the following endpoint to get any HTTP Status code and a description of the code:

https://foobar.rest/httpstatus/200

Replace the path parameter with any status code to get a response with that code and description. You can easily mock different status codes by calling that URL.

Example:

let url = "https://myrealapi.com/api/whatever"
//dev code
url = "https://foobar.rest/httpstatus/200"
let response = await fetch(url)
console.log(response)

Mock Data

Token Flows

The https://foobar.rest/token endpoint allows you to mock OAuth tokens. You can create a token, generate a refresh token, and authenticate - as well as CRUD operations.

Note: There is NO security, this is just for mocking. Making a GET request to /token will return ALL token data, for anyone. A DELETE request will also delete any token immediately.

Users

Mock users using the https://foobar.rest/users endpoint. CRUD operations available

Example user:

[
  {
    "id": "67eed9bd-3f6d-41e7-91a9-129659b91697",
    "createdAt": "2023-10-01T18:39:13.396Z",
    "updatedAt": "2023-10-01T18:39:13.396Z",
    "firstName": "Lorelai",
    "lastName": "Gilmore",
    "email": "lgilmore@StarsHollow.com",
    "title": "Co-owner and Manager of the Dragonfly Inn",
    "address": "214 Third Street, Stars Hollow CT 06794"
  }
]