RapidApi
Easily connect to RapidAPI blocks from your Elixir application.
Installation
- Add
rapid_apito your list of dependencies inmix.exs:
```elixir
def deps do
[{:rapid_api, "~> 0.1.0"}]
end
```
- Ensure
rapid_apiis started before your application:
```elixir
def application do
[applications: [:rapid_api]]
end
```
Add your configuration to your config/config.exs
config :rapid_api,base_url: "https://rapidapi.io", # optional - defaults to this URLtoken: "your-rapid-api-token",project: "your-rapid-api-project"
Usage
Synchronous calls
Connecting to RapidAPI is very simple. The following code makes a synchronous call to the getPictureOfTheDay function of the NasaAPI package, passing it the date parameter:
RapidAPI.call("NasaAPI", "getPictureOfTheDay", %{date: "1997-07-01"})
This will return a Map of the API response.
Asynchronous calls
To create an asynchronous call, you must first define a process that will receive the payload:
receiver = fn ->
receive do
data -> IO.puts inspect data
end
end
receiver_pid = spawn(receiver)
Then use the call_async function, passing it the relevant information as well as the receiver process's pid:
RapidApi.call_async("NasaAPI", "getPictureOfTheDay", receiver_pid, %{date: "1997-07-01"})
This will return :ok and once the request has returned, will send the data to the specified process.
License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.