You don't have to worry about form validation anymore, and write boilerplate code π©. This API handles validation out-of-the-box π¦! It's as simple as that.
Current version: 1.0
π API Base URL: https://forms-validation-api.vercel.app/api/v1.0
There are 4 endpoints to choose from.
You can expect a response with a status code of 400
(if validation failed), and 200
if succeded. More in the examples section.
Description | Method | Expected req.body | Endpoint |
---|---|---|---|
Validate password | POST |
{password: $value} |
/password |
Validate email address | POST |
{email: $value} |
/email |
Sign In Form | POST |
{email: $value, password: $value} |
/sign-in |
Sign Up Form | POST |
{email: $value, password: $value, confirmPassword: $value} |
/sign-up |
π Endpoint: /password
We check whether the password:
- is not empty,
- contains at least 8 characters,
- contains at least 1 digit,
- contains at least 1 capital letter,
- contains at least 1 special character.
π Endpoint: /email
We check whether the email address:
- is not empty,
- doesn't contain special characters such as
!#$%^&\*(),?\":{}|<>~^+/=
, - has no spaces,
- contains the
@
symbol, - does not have an additional
@
in the username portion, - does not contain offensive, vulgar, or inappropriate content (example words will not be mentioned here for ethical reasons).
π Endpoint: /sign-in
- validating both: email & password.
π Endpoint: /sign-up
- validating: email, password & password match.
In the example provided below, I am validating the user's password. The same analogy applies to each available form of validation.
const url = 'https://form-validation-api.vercel.app/api';
const reqConfig = (method: string, body: {}): {} => {
return {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
},
};
};
const validatePassword = async (password: string) => {
try {
const res = await fetch(`${url}/password`, reqConfig('POST', { password }));
const validationResult = await res.json();
if (!res.ok) throw new Error(validationResult.error); // if 400 code, 'error' key is available on the response object
//If we got here, it means that validation is successful
console.log(validationResult.success); //if 200 code, 'success' key is available on the res. object
} catch (error) {
console.log((error as Error).message);
}
};
Rate limiting is a strategy employed to restrict network traffic and prevent potential abuse of APIs. Each API route is equipped with its own rateLimiter
variable, which records the timestamps
of user requests. That, in essence, summarizes the concept.
The number of permitted requests per user, per minute for each API route is set at 10
.
Hey there, awesome folks! π I am on a mission to make magic happen, and I may need your collaboration superpowers! Let's team up, share ideas, and pool our talents to create something useful ππ«. Feel free to fork
repo and pull requests
or submit your request via issues
.
#CollaborationNation