Giter Club home page Giter Club logo

justifier-node-js's Introduction

Justifier service (Node.js)

Takes a text, and then converts it to text with 80 chars maximum per line.

Usage

  1. Create a user at /api/create-user Body example:
{
	"email": "[email protected]",
	"password": "qwertyisnotsafestpasswordintheworld"
}

You will have a return from server like:

{
  "email": "[email protected]",
  "wordsQuota": 80000
}

Where is email - is your email and wordsQuota - your words quota on this service

  1. Get a token

This service using JWT sessions Before using the justifier you have to request a token here /api/token. Body example:

{
	"email": "[email protected]",
	"password": "qwertyisnotsafestpasswordintheworld"
}

Example of response:

{
  "token": "eyJ0eXAi324.eyJpZCI6IkdwZFFQ3232CI6ImZvb0BiYXIuY29tbSIsImRhd32joxNjAzODQ0MDg13232wODU5NjgsImV4cGlyZXMiOjE2MDM4NDQ5ODU5Njh9.WHge090P-Am8OEArn8gnw5KBV_O0se71nhh_13moUmuorqUt6eQYBjLxy-tsDYx9323",
  "issued": 1603844085968,
  "expires": 1603844985968
}
  1. Justify your text Now we are ready to use the Justifier.

To form a request, set headers to:

Content-Type: text/plain
X-JWT-Token: yourtokenvaluefromthelaststep

Body example:

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

In response you will find the text in justified form

{
  "status": "success",
  "timestamp": 1603844128099,
  "text": "\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\nincididunt  ut  labore  et  dolore  magna  aliqua. Ut enim ad minim veniam, quis\nnostrud  exercitation  ullamco  laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu\nfugiat  nulla  pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n",
  "wordsQuota": 79611
}

After each usage your wordsQuota change.

If you will send a request to justify text and you dont have enough quota, then server will respond in this manner:

{
  "error": "You have to pay. Words to process: 5171, quota: 5029"
}

Pre-run instruction

Add your secret key to .env file or have it in-memory

You could find key names to use in .env.example

Run in development mode

npm run dev

Run in production mode

npm run build
npm run start

Insomnia

Also you could find insomnia file in this repo to test API from Insomnia client

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.