Je n'ai pas trouvé d'API permettant de demander un mot de la langue française en ligne.
Donc j'ai décidé de la faire moi-même.
La liste de mot que j'utilise a été téléchargé sur le site de 3Z Software, il s'agit de la liste Petit Larousse Illustré 2007 que l'on peut télécharger ici.
Cette API utilise une base de donnée MongoDB qui est dans un conteneur Docker.
Cloner le projet en local
Éxecuter le docker-compose avec la commande suivante afin de lancer le conteneur :
docker compose up -dDès que le conteneur est lancé, il faut remplir la base de donnée avec des mots.
Vouys avez deux options :
- Le faire à la main ( la base de donnée est accesible en
localhostsur le port27027) - Utiliser le fichier
populate.go, vous pouvez suivre les instructions du README qui se trouve dans le même dossier.
Une fois que la base de donnée est initialisé, vous pouvez executer le serveur.
Voici la liste des routes qui sont actuellement accessibles :
Tous les résultats de mots sont renvoyé sous cette forme :
{
"word": "festivals",
"length": 9,
"first_letter": "f",
"sorted_letter": "aefilsstv"
}Renvoie tous les mots qui commencent par la lettre fournie
Erreur possible
- Si la lettre fournie ne fait pas 1 caractère, une erreur sera renvoyé :
400 Bad Request
{
"error": "Invalid first letter. Expected one character."
}Exemple : words/abc renverra cette erreur.
- Si aucun mot ne commence par la lettre fournie, une erreur sera renvoyé :
404 Not Found
{
"error": "No words start with a (╚)"
}Exemple : words/╚ renverra cette erreur.
Renvoie un mot choisi aléatoirement qui commence par la lettre fournie.
Erreur possible
- Si la lettre fournie ne fait pas 1 caractère, une erreur sera renvoyé :
400 Bad Request
{
"error": "Invalid first letter. Expected one character."
}Exemple : word/abc renverra cette erreur.
- Si aucun mot ne commence par la lettre fournie, une erreur sera renvoyé :
404 Not Found
{
"error": "No words start with a (╚)"
}Exemple : word/╚ renverra cette erreur.
Renvoie un mot choisi aléatoirement qui a la longueur demandée
Erreur possible
- Si la longueur fournie n'est pas un nombre, une erreur sera renvoyé :
400 Bad Request
{
"error": "Please give a number"
}Exemple : word/length/a renverra cette erreur.
- Si aucun mot avec la longueur fournie n'est trouvé, une erreur sera renvoyé :
404 Not Found
{
"error": "No words with length (111)"
}Exemple : word/length/111 renverra cette erreur.
Renvoie tous les anagrammes du mot fourni
Erreur possible
- Si le mot fourni n'a pas d'anagramme, une erreur sera renvoyé :
404 Not Found
{
"error": "No anagram found for this word (aaaaaaaa)"
}Exemple : anagrams/aaaaaaaa renverra cette erreur.
Renvoie pour chaque lettre fournie, un mot qui commence par cette lettre
Erreur possible
- Si aucune des lettres ne permet de trouver un mot, une erreur sera renvoyé :
404 Not Found
{
"error": "No words start with given letters (é&)"
}Exemple : words-batch/&é renverra cette erreur.
Vérifie si le mot fourni existe dans la base de donnée.
{
"word": "motàvérifier"
}Erreur possible
Si le mot n'est pas fourni dans le body, une erreur sera renvoyé : `400 Bad Request`{
"error": "Word is required",
"example": {
"word": "example"
}
}I couldn't find an API allowing me to request a word of the French language online.
So I decided to do it myself.
The word list that I use was downloaded from the 3Z Software website, this is the list Petit Larousse Illustré 2007 which can be downloaded here.
This API uses a MongoDB database, which is in a Docker container.
Clone the project in local
Run the docker-compose file with the following command to launch the container:
docker compose up -dAs soon as the container is launched, you must fill the database with words.
You have two options:
- Do it by hand (the database is accessible via
localhoston port27027) - Use the file
populate.go, you can follow the instructions in the README which is located in the same folder.
Once the database is initialized, you can run the server.
Here is the list of routes that are currently accessible:
All word results are returned in this form:
{
"word": "festivals",
"length": 9,
"first_letter": "f",
"sorted_letter": "aefilsstv"
}Returns all words that start with the letter provided
Error possible
- If the letter provided is not one character long, an error will be returned:
400 Bad Request
{
"error": "Invalid first letter. Expected one character."
}Example: words/abc will return this error.
- If no word begins with the letter provided, an error will be returned:
404 Not Found
{
"error": "No words start with a (╚)"
}Example : words/╚ will return this error.
Returns a randomly chosen word that begins with the letter provided.
Possible error
- If the letter provided is not one character long, an error will be returned:
400 Bad Request
{
"error": "Invalid first letter. Expected one character."
}Example: word/abc will return this error.
- If no word begins with the letter provided, an error will be returned:
404 Not Found
{
"error": "No words start with a (╚)"
}Example : word/╚ will return this error.
Returns a randomly chosen word that has the requested length
Possible error
- If the length provided is not a number, an error will be returned:
400 Bad Request
{
"error": "Please give a number"
}Example: word/length/a will return this error.
- If no word with the provided length is found, an error will be returned:
404 Not Found
{
"error": "No words with length (111)"
}Example: word/length/111 will return this error.
Returns all anagrams of the word provided
Possible error
- If the word provided does not have an anagram, an error will be returned:
404 Not Found
{
"error": "No anagram found for this word (aaaaaaaa)"
}Example: anagrams/aaaaaaaa will return this error.
Returns for each letter provided, a word that begins with that letter
Possible error
- If none of the letters allow finding a word, an error will be returned:
404 Not Found
{
"error": "No words start with given letters (é&)"
}Example: words-batch/&é will return this error.
Check if the provided word exists in the database.
{
"word": "wordtocheck"
}Possible error
If the word is not provided in the body, an error will be returned: `400 Bad Request`{
"error": "Word is required",
"example": {
"word": "example"
}
}