Express server to submit and check form submissions. Built with Node, TypeScript, TypeORM, and Postgres.
Install dependencies:
npm install
Start postgres
docker container:
docker-compose up -d
Seed with example form and fields:
npm run seed
Start form submission server:
npm run start
Currently supported:
string
andnumber
field types, can be optional and requiredminLength
/maxLength
andmin
/max
constraints for string/number fields respectively.- basic form submission validation (all required fields are provided and all defined constraints are met) with detailed error messages for each case
- a simple user form for name and age submission
Possible extentions:
- An admin panel to edit existing form templates and create new ones.
- More field types like specific strings (emails, phone numbers with their own validations), files, or single-select/multi-select.
- Grouped fields.
- Form-level validations.
- More constraint types.
- Submission of invalid forms for later editing.
Query all forms:
curl localhost:8080/forms
Query one form:
curl localhost:8080/forms/1
Query all form submissions:
curl localhost:8080/submissions
Query one form submission:
curl localhost:8080/submissions/1
only required fields
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "2", "value": "Marktanner"},
{"id": "4", "value": "31"}
]
}
'
all fields, required and optional
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "2", "value": "Marktanner"},
{"id": "3", "value": "A second submission"},
{"id": "4", "value": "31"}
]
}
'
misses formId
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"id": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "4", "value": "31"}
]
}
'
misses fields
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"myFields": [
{"id": "1", "value": "Nilan"},
{"id": "4", "value": "31"}
]
}
'
required field is missing
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "4", "value": "31"}
]
}
'
string too short
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": ""},
{"id": "2", "value": "Marktanner"},
{"id": "4", "value": "31"}
]
}
'
string too long
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "2", "value": "MarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktannerMarktanner"},
{"id": "4", "value": "31"}
]
}
'
number too small
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "2", "value": "Marktanner"},
{"id": "4", "value": "0"}
]
}
'
number too large
curl -X POST localhost:8080/submit -H "Content-Type: application/json" -d \
'
{
"formId": 1,
"fields": [
{"id": "1", "value": "Nilan"},
{"id": "2", "value": "Marktanner"},
{"id": "4", "value": "2000"}
]
}
'