A modern .NET client library for the Lexicala Dictionary API. Lexicala provides comprehensive linguistic data including translations, definitions, pronunciations, and more across multiple languages.
- .NET 8.0 or .NET 10.0 runtime
- A RapidAPI account with an API key for Lexicala (sign up at RapidAPI)
Install the package via NuGet:
dotnet add package Lexicala.NETOr using the Package Manager Console:
Install-Package Lexicala.NET- Sign up for a RapidAPI account at rapidapi.com
- Subscribe to the Lexicala API
- Copy your API key from the RapidAPI dashboard
Add the Lexicala configuration to your appsettings.json:
{
"Lexicala": {
"ApiKey": "your-rapidapi-key-here",
"UseLiteEndpoints": false
}
}Set UseLiteEndpoints to true if your subscription only allows Lite entry/sense endpoints. When enabled, the client automatically uses:
/search-entries-liteinstead of/search-entries/entries-lite/{entryId}instead of/entries/{entryId}/senses-lite/{senseId}instead of/senses/{senseId}
In your Program.cs (for .NET 6+):
usingLexicala.NET;varbuilder=WebApplication.CreateBuilder(args);// Register Lexicala servicesbuilder.Services.RegisterLexicala(builder.Configuration);varapp=builder.Build();// ... rest of your setup- .NET 8.0
- .NET 10.0
After configuration, you can inject ILexicalaClient or ILexicalaSearchParser into your services.
// Inject ILexicalaClientpublicclassTranslationService{privatereadonlyILexicalaClient_client;publicTranslationService(ILexicalaClientclient){_client=client;}publicasyncTask<string>TranslateWordAsync(stringword,stringfromLang,stringtoLang){varsearchResponse=await_client.BasicSearchAsync(word,fromLang);if(searchResponse.Results.Any()){varentry=await_client.GetEntryAsync(searchResponse.Results.First().Id);// Translations is Dictionary<string, TranslationObject> keyed by 2-letter language codevarsense=entry.Senses.FirstOrDefault(s =>s.Translations.ContainsKey(toLang));if(senseis not null&&sense.Translations.TryGetValue(toLang,outvartranslationObj)){returntranslationObj.Translation?.Text??translationObj.Translations?.FirstOrDefault()?.Text??"Translation not found";}}return"Word not found";}}varlanguagesResponse=awaitlexicalaClient.LanguagesAsync();varglobalLanguages=languagesResponse.Resources.Global;Console.WriteLine($"Available languages: {string.Join(", ",globalLanguages.SourceLanguages)}");// Search for "hello" in EnglishvarsearchResponse=awaitlexicalaClient.BasicSearchAsync("hello","en");foreach(varresultinsearchResponse.Results){varheadwordText=result.Headword?.Headword?.Text??result.Headword?.HeadwordElementArray?.FirstOrDefault()?.Text??"(no headword)";Console.WriteLine($"Found: {headwordText} (ID: {result.Id})");}varadvancedRequest=newAdvancedSearchRequest{Language="en",SearchText="run",Pos="verb"// Part of speech filter};varadvancedResponse=awaitlexicalaClient.AdvancedSearchAsync(advancedRequest);foreach(varresultinadvancedResponse.Results){varentry=awaitlexicalaClient.GetEntryAsync(result.Id);// Process detailed entry information}The ILexicalaSearchParser provides a higher-level abstraction for easier parsing:
// Inject ILexicalaSearchParserpublicclassSearchService{privatereadonlyILexicalaSearchParser_parser;publicSearchService(ILexicalaSearchParserparser){_parser=parser;}publicasyncTask<SearchResultModel>SearchAndParseAsync(stringterm,stringlanguage){returnawait_parser.SearchAsync(term,language);}}// Usagevarresult=awaitsearchService.SearchAndParseAsync("árbol","es");varenglishSummary=result.Summary("en");// "tree, shaft, post, mast"foreach(varsearchResultinresult.Results){vardefinition=searchResult.Senses.FirstOrDefault()?.Definition;Console.WriteLine($"Definition: {definition}");}varentry=awaitlexicalaClient.GetEntryAsync("EN00001234");// Example IDforeach(varsenseinentry.Senses){Console.WriteLine($"Sense: {sense.Definition}");}foreach(varheadwordinentry.Headwords){foreach(varproninheadword.Pronunciations){Console.WriteLine($"Pronunciation: {pron.Value}");}}The repository includes an ASP.NET Core minimal Web API demo host with Swagger UI for testing all endpoints.
Clone the repository and navigate to the demo API:
cd source/Demo/Lexicala.NET.Demo.ApiConfigure your Lexicala API key. Choose one of the following:
Recommended: Use User Secrets
dotnet user-secrets init dotnet user-secrets set"Lexicala:ApiKey""your-rapidapi-key-here"
Alternative: Edit appsettings.json
Open
appsettings.jsonin the demo API folder and add:{ "Lexicala": { "ApiKey": "your-rapidapi-key-here", "UseLiteEndpoints": false } }Run the application:
dotnet run
Open Swagger UI in your browser:
- HTTP:
http://localhost:5000/swagger - HTTPS:
https://localhost:5001/swagger
- HTTP:
To use the Sense Sprint web app, see the Sense Sprint documentation for setup and gameplay details.
Available endpoints:
GET /test- Test API connectivityGET /languages- Get available languagesGET /search- Basic searchGET /search-entries- Basic search with full entriesGET /search-entries-lite- Basic search with full entries in lite mode (UseLiteEndpoints=true)GET /search-rdf- Basic search in RDF/JSON-LD formatGET /search-definitions- Free-text search in definitionsGET /fluky-search- Random word discoveryGET /entries/{entryId}- Get dictionary entry by IDGET /entries-lite/{entryId}- Get dictionary entry by ID in lite mode (UseLiteEndpoints=true)GET /senses/{senseId}- Get sense by IDGET /senses-lite/{senseId}- Get sense by ID in lite mode (UseLiteEndpoints=true)GET /rdf/{entryId}- Get entry in RDF/JSON-LD formatPOST /search-advanced- Advanced searchPOST /search-entries-advanced- Advanced search with full entriesPOST /search-rdf-advanced- Advanced search in RDF/JSON-LD format
Missing endpoints compared to Rapid Api test console / Lexicala MCP tooling - these endpoints are NOT listed in the official documentation!:
GET /abbreviationsGET /reverse-abbreviationsGET /antonymsGET /definitionsGET /examplesGET /frequenciesGET /phrasesGET /pronunciationsGET /registersGET /semantic-categoriesGET /subcategorizationsGET /synonymsGET /translate-toGET /translate-exampleGET /translate-phrase
For React frontend development, CORS is enabled for:
http://localhost:3000http://localhost:5173
A dedicated React + Vite frontend for a word guessing game is available at source/Demo/sense-sprint-web.
The web demo currently includes two game modes. Sense Sprint is the lower-cost mode. Translation Quiz makes more Lexicala calls per round because it has to source a word, fetch its entry, and build multiple distractor choices. If you are using a free evaluation subscription, use Translation Quiz sparingly.
Start the backend API (see Testing with Swagger UI above)
In another terminal, navigate to the frontend:
cd source/Demo/sense-sprint-webInstall dependencies and start the dev server:
PowerShell:
npm.cmd install npm.cmd run dev
Bash / Command Prompt:
npm install npm run dev
Open the app at
http://localhost:5173
For complete game documentation, features, and tips, see the Sense Sprint README.
Clone the repository:
git clone https://github.com/HannoZ/Lexicala.NET.git cd Lexicala.NETBuild the solution:
dotnet build source/Lexicala.NET.slnx
Run tests:
dotnet test source/Lexicala.NET.slnx
The legacy source/Lexicala.NET.sln file has been removed in favor of source/Lexicala.NET.slnx.
The library validates and supports these commonly used API parameter values:
sourcevalues forFlukySearchAsyncandAdvancedSearch*Async:global,password,random,multigloss- Language parameters (
language,sourceLanguage) must be 2-character language codes AdvancedSearchRequest.Pageaccepts values up to1000AdvancedSearchRequest.Sampleaccepts values up to1000AdvancedSearchRequest.PageLengthaccepts values between1and30(default10)
The library implements the following Lexicala API endpoints:
Utility Endpoints
/test- Test API connectivity/languages- Get available languages
Search Endpoints
/search- Basic search/search-entries- Search with full entries/search-entries-lite- Search with full entries in lite mode (UseLiteEndpoints=true)/search-rdf- Search in RDF/JSON-LD format/search-definitions- Free-text search in definitions/fluky-search- Random word discovery
Advanced Search Endpoints
/search-advanced- Advanced search with custom parameters/search-entries-advanced- Advanced search with full entries/search-rdf-advanced- Advanced search in RDF/JSON-LD format
Entry and Sense Endpoints
/entries- Get entry details by ID/entries-lite- Get entry details by ID in lite mode (UseLiteEndpoints=true)/senses- Get sense details by ID/senses-lite- Get sense details by ID in lite mode (UseLiteEndpoints=true)/rdf- Get entry in RDF/JSON-LD format
For complete API documentation, visit the Lexicala API Documentation.
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.