8000 initial commit · maciejkuran/forms-validation-API@0e01805 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e01805

Browse files
committed
initial commit
0 parents  commit 0e01805

15 files changed

+4034
-0
lines changed

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Form Validation API ⚡
2+
3+
<p align="center">
4+
<img width="200" src="/public/icon.png">
5+
</p>
6+
7+
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.
8+
9+
🔗 API URL: `https://form-validation-api.vercel.app/api`
10+
11+
## API Endpoints
12+
13+
There are 4 endpoints to choose from.
14+
You can expect a response with a status code of `400` (if validation failed), and `200` if succeded. More in the examples section.
15+
16+
| Description | Endpoint |
17+
| ---------------------------------------------- | -------------- |
18+
| Validate password | /password |
19+
| Validate email address | /email-address |
20+
| Sign In Form (email, password) | /sign-in-form |
21+
| Sign Up Form (email, password, password match) | /sign-up-form |
22+
23+
### Validating Only Password 🔑
24+
25+
👉 Endpoint: `/password`
26+
27+
We check whether the password:
28+
29+
- is not empty,
30+
- contains at least 8 characters,
31+
- contains at least 1 digit,
32+
- contains at least 1 capital letter,
33+
- contains at least 1 special character.
34+
35+
### Validating Only Email Address 📧
36+
37+
👉 Endpoint: `/email-address`
38+
39+
We check whether the email address:
40+
41+
- is not empty,
42+
- doesn't contain special characters such as `!#$%^&\*(),?\":{}|<>~^+/=`,
43+
- has no spaces,
44+
- contains the @ symbol,
45+
- does not have an additional @ in the username portion,
46+
- does not contain offensive, vulgar, or inappropriate content (example words will not be mentioned for ethical reasons).
47+
48+
### Sign In Form Validation
49+
50+
👉 Endpoint: `/sign-in`
51+
52+
- validating both: email & password.
53+
54+
### Sign Up Form Validation
55+
56+
👉 Endpoint: `/sign-up`
57+
58+
- validating: email, password & password match.
59+
60+
## Example
61+
62+
In the example provided below, I am validating the user's password. The same analogy applies to each available form of validation.
63+
64+
```
65+
const url = 'https://form-validation-api.vercel.app/api';
66+
67+
const reqConfig = (method: string, body: {}): {} => {
68+
return {
69+
method: 'POST',
70+
body: body,
71+
headers: {
72+
'Content-Type': 'application/json',
73+
},
74+
};
75+
};
76+
77+
const validatePassword = async (password: string) => {
78+
try {
79+
const res = await fetch(`${url}/password`, reqConfig('POST', { password: password }));
80+
const validationResult = await res.json();
81+
82+
if (!res.ok) throw new Error(validationResult.error); // if 400 code, 'error' key is available on the response object
83+
84+
//If we got here, it means that validation is successful
85+
console.log(validationResult.success); //if 200 code, 'success' key is available on the res. object
86+
} catch (error) {
87+
console.log((error as Error).message);
88+
}
89+
};
90+
91+
```
92+
93+
## Rate Limit Middleware
94+
95+
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.
96+
97+
The number of permitted requests per user, per minute for each API route is set at `10`.
98+
99+
## Contribution
100+
101+
Hey there, awesome folks! 👋 We're on a mission to make magic happen, and we 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`.
102+
103+
#CollaborationNation

next.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)
0