View Source JikanEx (JikanEx v0.1.6)
A thin elixir wrapper for the Jikan API. Start by creating a JikanEx.client/1
, which is then passed to each request (see JikanEx.Request
).
You can set the base url to use in your application configuration:
# config/config.exs
import Config
config :jikan_ex,
base_url: "http://localhost:8000/v3/"
If you're self-hosting an instance of Jikan and have issue connecting to the server, start it so that its accessible from any machine, like:
php -S 0.0.0.0:25639 -t public
Quickstart
alias JikanEx.Request
client = JikanEx.client()
response = client |> Request.anime!(1)
IO.puts response["title"] # Prints 'Cowboy Bebop'
If you're having JSON-parsing related errors, you may have to recompile Tesla
with Jason
, see Tesla.Middleware.JSON
Summary
Functions
Creates a new Jikan client. Attempts to get the base url from your application config. If that doesn't exist, uses the remote api.jikan.moe
endpoint.
Functions
@spec client(List.t()) :: Telsa.Client.t()
Creates a new Jikan client. Attempts to get the base url from your application config. If that doesn't exist, uses the remote api.jikan.moe
endpoint.
You can optionally pass a keyword list with options instead.
Returns Tesla.Client
Examples
iex> JikanEx.client()
%Tesla.Client{
adapter: nil,
fun: nil,
post: [],
pre: [{Tesla.Middleware.BaseUrl, :call, ["https://api.jikan.moe/v3/"]}]
}
iex> Application.put_env(:jikan_ex, :base_url, "http://localhost:8000/v3/")
iex> JikanEx.client()
%Tesla.Client{
adapter: nil,
fun: nil,
post: [],
pre: [{Tesla.Middleware.BaseUrl, :call, ["http://localhost:8000/v3/"]}]
}
iex> Application.delete_env(:jikan_ex, :base_url)
iex> JikanEx.client([base_url: "http://localhost:8000/v3/"])
%Tesla.Client{
adapter: nil,
fun: nil,
post: [],
pre: [{Tesla.Middleware.BaseUrl, :call, ["http://localhost:8000/v3/"]}]
}