Code Monkey home page Code Monkey logo

forms-validation-api's Introduction

Forms Validation API โšก

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

๐Ÿ”— Documentation


API Endpoints

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

Validating Only Password ๐Ÿ”‘

๐Ÿ‘‰ 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.

Validating Only Email Address ๐Ÿ“ง

๐Ÿ‘‰ 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).

Sign In Form Validation

๐Ÿ‘‰ Endpoint: /sign-in

  • validating both: email & password.

Sign Up Form Validation

๐Ÿ‘‰ Endpoint: /sign-up

  • validating: email, password & password match.

Example

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 Limit Middleware

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.

Contribution

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

forms-validation-api's People

Contributors

maciejkuran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.