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.
- Secure token-based authentication.
- Text justification.
- Daily word count rate limit.
- Built-in rate limiter for API requests.
Ensure that you have the following installed:
- Node.js
- npm (comes with Node.js)
- Clone the repository:
git clone https://github.com/Vehementz/postApi.git
- Navigate to the project directory:
cd cd postApi
- Install dependencies:
npm install
- 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.
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
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.
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
- Each user is rate-limited to 80,000 words per day.
- API requests are limited to 100 requests per 15 minutes.
- Uses JSON Web Tokens (JWT) for authentication.
- Implements rate limits to prevent abuse.
- Sanitizes text input to prevent malicious code execution.