Skip to main content

Update 3 Objects, Enums, and Colors

ยท 2 min read
Carl Sparks
One man band

We're back with another update! This time, we're introducing some of the most requested features to Mockd: custom objects, object arrays, enums, and color support.

๐Ÿ—๏ธ Custom Objects (object)โ€‹

You can now define your own custom types using the types field in your request. This is perfect for when you need a specific structure for your data.

How to use it:โ€‹

  1. Define your custom structure in the types object.
  2. Reference your custom type in the fields object using object-[typeName].
POST Body
{
"types": {
"User": {
"id": "uuidv4",
"name": "male-full-name",
"email": "email"
}
},
"fields": {
"admin": "object-[User]"
}
}

๐Ÿ—ƒ๏ธ Object Arrays (object-array)โ€‹

Need a list of those custom objects? object-array has you covered. It works just like the array type but for your custom defined types.

How to use it:โ€‹

Reference your custom type using object-array-[typeName(size)].

POST Body
{
"types": {
"Product": {
"sku": "mask-[AAA-####]",
"price": "money"
}
},
"fields": {
"inventory": "object-array-[Product(3)]"
}
}

๐Ÿ”ข Enums (enum)โ€‹

The enum type allows you to provide a list of specific values, and Mockd will randomly select one for you.

How to use it:โ€‹

Provide a comma-separated list of values inside square brackets: enum-[value1,value2,value3].

POST Body
{
"fields": {
"status": "enum-[pending,active,completed,cancelled]"
}
}

๐ŸŽจ Color (color-hex)โ€‹

Adding some visual flair to your mocks? The color-hex type generates a random hexadecimal color string.

How to use it:โ€‹

Simply use color-hex as the field type.

POST Body
{
"fields": {
"primaryColor": "color-hex"
}
}

We hope these new types help you build even better things with Mockd! As always, if you have any feedback or feature requests, feel free to reach out.