Add HTML note in README, tweak swagger def

This commit is contained in:
Piero Toffanin 2021-09-11 16:02:10 -04:00
parent 0a7c8ebae9
commit a41f5671b0
2 changed files with 37 additions and 3 deletions

View file

@ -12,6 +12,9 @@ Free and Open Source Machine Translation API, entirely self-hosted. Unlike other
## API Examples
### Plain Text
Request:
```javascript
@ -36,6 +39,33 @@ Response:
}
```
### HTML
Request:
```javascript
const res = await fetch("https://libretranslate.com/translate", {
method: "POST",
body: JSON.stringify({
q: '<a href="#" class="green">Hello!</a>',
source: "en",
target: "es",
format: "html"
}),
headers: { "Content-Type": "application/json" }
});
console.log(await res.json());
```
Response:
```javascript
{
"translatedText": "<a href\"#='class=\"green\"'>¡Hola!</a>"
}
```
## Install and Run
You can run your own API server in just a few lines of setup!
@ -136,7 +166,6 @@ You can pass application arguments directly to Gunicorn via:
gunicorn --bind 0.0.0.0:5000 'wsgi:app(api_keys=True)'
```
## Manage API Keys
LibreTranslate supports per-user limit quotas, e.g. you can issue API keys to users so that they can enjoy higher requests limits per minute (if you also set `--req-limit`). By default all users are rate-limited based on `--req-limit`, but passing an optional `api_key` parameter to the REST endpoints allows a user to enjoy higher request limits.

View file

@ -267,9 +267,14 @@ def create_app(args):
name: format
schema:
type: string
example: html or text
enum: [text, html]
default: text
example: text
required: false
description: The format of the source text
description: >
Format of source text:
* `text` - Plain text
* `html` - HTML markup
- in: formData
name: api_key
schema: