team-genny / genny

0 stars 1 forks source link

Add API endpoint to generate and persist generated data #6

Closed fergcb closed 4 months ago

fergcb commented 4 months ago

An endpoint should be added to allow users to generate data against a given schema, with the data being stored in the mongodb database so that it can be recalled later.

POST /api/data

Request Body

{
  "schema": "<schema id or slug>",
  "count": XX, // # records to generate
  "slug": "<slug of generated data>"
}

schema specifies which schema to use to generate the data. It can be a human-facing slug or an ID.

count specifies how many records to generate. This is optional, default to 50.

slug specifies a human-facing identifier for the generated data. This is optional, no default.

Responses

400 Bad Request

Returned if request body is invalid, e.g. slug conflict, malformed JSON, invalid values, formula/schema errors.

{
  "error": "<validation error message>",
  "details": {
    // Optional additional details
  }
}

201 Created

{
  "_id": "<mongodb ObjectId>"
  "slug": "<optional slug for data>"
  "schema": {
    "_id": "<schema mongodb ObjectId>"
    "slug": "<schema slug>"
  },
  "data": [
    // List of generated data
  ]
}