Giter VIP home page Giter VIP logo

justify-text-node's Introduction

Text Justification API

The Text Justification API is a Node.js application that provides text justification services. Clients can send a piece of text to the API, which returns the text justified to fit within a specific width.

Features

  • Secure token-based authentication.
  • Text justification.
  • Daily word count rate limit.
  • Built-in rate limiter for API requests.

Getting Started

Prerequisites

Ensure that you have the following installed:

  • Node.js
  • npm (comes with Node.js)

Installation

  1. Clone the repository:
git clone https://github.com/Vehementz/postApi.git
  1. Navigate to the project directory:
cd cd postApi
  1. Install dependencies:
npm install
  1. Start the server for developpement:
npm run dev

OR with docker

npm run docker:dev

FOR Production

npm run docker:prod

The API should be running and listening on port 8080.

Usage

Local

Requesting a Token

Insomnia

POST REQUEST at the address

http://localhost:8080/api/token

In the body use the JSON format and use something like below

{
  "email": "[email protected]"
}

A token is returned

After

Send a POST request at the address http://localhost:8080/api/justify

In the body use something like below

{
  "text": "Your text to be justified goes here. Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here.Your text to be justified goes here."
}

In the headers use :

  • Content-Type : text/plain
  • Authorization : Bearer YOUR_TOKEN

The text is returned justified

A curl request to generate a token

To make justified text requests, a token is needed. Obtain a token:

curl -X POST -H "Content-Type: application/json" --data '{"email": "[email protected]"}' http://localhost:8080/api/token

The API will respond with a token. Use this token for subsequent requests.

Justifying Text

Send a piece of text for justification:

curl -X POST \
-H "Authorization: Bearer YOUR_COPIED_TOKEN" \
-H "Content-Type: text/plain" \
--data "Your text content here" \
http://localhost:8080/api/justify

Replace YOUR_TOKEN with the token you received.

Exemple : generate a token

curl -X POST -H "Content-Type: application/json" --data '{"email": "[email protected]"}' http://localhost:8080/api/token

Return something like => "eyJhbGciOiJIUzI1hrtregsthtrt.tghuqhjgrhiqrthiogqrhjkmFLEHZECEHgrniozejviHIHghaeijgrhjgrhquhrhjgqlzerhhkkfeqlhzefhlefhjghjehfjkqfhuhaqhpe"

Exemple : Justify the text

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InlvdXJfZW1haWxAZG9tYWluLmNvbSIsImlhdCI6MTY5ODUwMDI0MywiZXhwIjoxNjk4NTg2NjQzfQ.pcXtWYb6T190tOngVAF-Lae4vkU230sQ0XnTWGm5UoI" \
--data '{"text":"Your text to be justified goes here."}' \
http://localhost:8080/api/justify

Rate Limits

  • Each user is rate-limited to 80,000 words per day.
  • API requests are limited to 100 requests per 15 minutes.

Security

  • Uses JSON Web Tokens (JWT) for authentication.
  • Implements rate limits to prevent abuse.
  • Sanitizes text input to prevent malicious code execution.

justify-text-node's People

Contributors

vehementz 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.