Skip to content

This is a web service, with REST APIs, that justifies text passed as a parameter

Notifications You must be signed in to change notification settings

Sarrabah/justify-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents

Description

This is a web service, with REST APIs, that justifies text passed as a parameter

Features

This service provides users required REST APIs that allow:

  • JWT-based authentication for obtaining tokens.
  • Text justification based on 80 per line.
  • Rate limiting for text justification to control usage (80000 word per token per day).

Getting Started

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js and npm installed.

Installation

  1. Clone this repository.
git clone https://github.com/Sarrabah/justify-text.git
  1. Navigate to the project directory.
cd justify-text
  1. Install dependencies.
npm install
  1. Set the required environment variables by creating a .env file with the following content, and replacing your_secret_key with your desired secret key for JWT token generation:
JWT_SECRET=your_secret_key
  1. Start the server:
npm run dev

Usage

API Routes

/api/token

  • Method: POST
  • Description: Get a JSON Web Token (JWT) by providing an email. You will receive a token in response, which you should include in the Authorization header for subsequent requests.
  • Request Body:
    {
      "email": "foo@bar.com"
    }
  • Response:
    {
      "token": "your-jwt-token"
    }

/api/justify

  • Method: POST
  • Description: Justify text provided in the request body.
  • Request Body: Text to be justified, as a plain/text.
  • Response: Justified text, as a plain text.
  • Contraints: Text justification should be authentificated and it is rate-limited. You will receive a 402 Payment Required status code if you exceed the limit.

Demo

A demo has been deployed on a heroku instance URL: https://justify-text-demo-d45e0d48f948.herokuapp.com/

Follow up ideas

  • Have a flexible way to easily configure the width of the line when jutifying text
  • Persist the rate limit per token
  • Improve the expiration management of the tokens
  • Adding more tests, mainly for middlewares

About

This is a web service, with REST APIs, that justifies text passed as a parameter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published