urban-rs: API for Urban Dictionary
An async API to interact with Urban Dictionary to get definitions from it.
The API Uses reqwest for fetching definitions off of the internet
There are three ways to get a definition:
- by word
- by id
- randomly
Example
use io;
use Runtime;
println!;
let mut word = String new;
stdin
.read_line
.expect;
// A reqwest client is needed to use the urban API
let client = new;
// The function is async. Thus it needs an executor to be ran from inside a non-async
// function.
if let Ok = new
.expect
.block_on
else
This example asks a user for a word and prints out its definition
Guide
To start using urban-rs. Add it to your cargo.toml
= "0.1.0"
Urban-rs uses reqwest
to fetch definitions trough the internet asynchronously.
This means that you will need to use a reqwest::Client
to give to the functions.
The reasons for the user to provide a client is so that it can be reused across multiple function calls.
Or even across different APIs that all need a reqwest client.
Aditionally, since the functions are asynchronous, they won't directly return a result.
But instead will return a Future that needs to be executed.
Using futures
's executors won't work. As reqwest requires tokios runtime to be executed.
Thus the futures returned from the functions need to be called trough tokio
's Runtime
and its executors.
use Runtime;
// A reqwest client is needed so that the Urban API can make web API calls
let client = new;
// As stated before. The API uses async functions which return futures. These need to be executed trough
// tokio's Runtime.
if let Ok = new
.expect
.block_on
else