Skip to content

Used for Text Corrections, built using Hono, Reverse Engineered Grammarly API and Zod

Notifications You must be signed in to change notification settings

devfxx/Corrections

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grammarly API Service

A lightweight API service that provides text correction and grammar checking capabilities using a Reverse Engineered Grammarly API. Built with Hono.js for optimal performance and reliability.

Features

  • Text correction and grammar checking
  • Automatic spacing and punctuation formatting
  • Error handling and input validation
  • RESTful API endpoints

API Reference

Correct Text

Analyzes and corrects the provided text using Grammarly's engine.

Endpoint: POST /correct

Request Body:

{
  "text": "Your text here"
}

Success Response:

{
  "error": false,
  "message": "Your corrected text here"
}

Error Responses:

Invalid Request (400):

{
  "error": true,
  "message": "Invalid request body"
}

Server Error (500):

{
  "error": true,
  "message": "Internal server error"
}

Default Route

Returns a friendly greeting message for all other routes.

Endpoint: GET *

Response:

{
  "error": false,
  "message": "Hi there!"
}

How It Works

  1. Input Validation

    • The service validates incoming requests using Zod schema validation
    • Ensures the text field is present and non-empty
  2. Text Analysis

    • Sends the text to Grammarly's API for analysis
    • Implementation: src/index.ts
  3. Text Transformation The service applies several transformations to the text:

    a. Correction Application

    • Processes each alert from Grammarly
    • Applies suggested corrections sequentially
    • Updates positions of subsequent corrections to account for text length changes
    • Implementation: src/lib/transform.ts

    b. Final Formatting

    • Ensures proper spacing after punctuation
    • Removes excessive spaces
    • Trims the final result
    • Implementation: src/lib/transform.ts

Error Handling

The service implements comprehensive error handling:

  1. Request Validation Errors

    • Validates request body schema
    • Returns 400 status code for invalid requests
  2. Server Errors

    • Catches and logs unexpected errors
    • Returns 500 status code with a generic error message
    • Prevents sensitive error information from reaching the client

License

MIT

About

Used for Text Corrections, built using Hono, Reverse Engineered Grammarly API and Zod

Resources

Stars

Watchers

Forks