# cUrl As A Service ### Overview [Curl](https://curl.se) is a widely available and used command-line tool to receive or send data using URL syntax. Chances are, you probably just used it when you set up your Fluence development environment. For Fluence services to be able to interact with the world, cUrl is one option to facilitate https calls. Since Fluence modules are Wasm IT modules, cUrl cannot not be a service intrinsic. Instead, the curl command-line tool needs to be made available and accessible at the node level. And for Fluence services to be able to interact with Curl, we need to code a cUrl adapter taking care of the mounted (cUrl) binary. ### Adapter Construction The work for the cUrl adapter has been fundamentally done and is exposed by the Fluence Rust SDK. As a developer, the task remaining is to instantiate the adapter in the context of the module and services scope. The following code [snippet](https://github.com/fluencelabs/marine/tree/master/examples/url-downloader/curl\_adapter) illustrates the implementation requirement. It is a part of a larger service, [url-downloader](https://github.com/fluencelabs/marine/tree/master/examples/url-downloader). ```rust use marine_rs_sdk::marine; use marine_rs_sdk::WasmLoggerBuilder; use marine_rs_sdk::MountedBinaryResult; pub fn main() { WasmLoggerBuilder::new().build().unwrap(); } #[marine] pub fn download(url: String) -> String { log::info!("download called with url {}", url); let result = unsafe { curl(vec![url]) }; String::from_utf8(result.stdout).unwrap() } #[marine] #[link(wasm_import_module = "host")] extern "C" { fn curl(cmd: Vec) -> MountedBinaryResult; } ``` with the following dependencies necessary in the Cargo.toml: ```rust marine-rs-sdk = { version = "=0.6.11", features = ["logger"] } log = "0.4.8" ``` We are basically linking the [external](https://doc.rust-lang.org/std/keyword.extern.html) cUrl binary and are exposing access to it as a `marine` interface called download. ### Code References * [Mounted binaries](https://github.com/fluencelabs/fce/blob/c559f3f2266b924398c203a45863ebf2fb9252ec/fluence-faas/src/host\_imports/mounted\_binaries.rs) * [cUrl](https://github.com/curl/curl) ### Service Construction In order to create a valid Fluence service, a service configuration is required. ``` modules_dir = "target/wasm32-wasi/release" [[module]] name = "curl_adapter" logger_enabled = true [module.mounted_binaries] curl = "/usr/bin/curl" ``` We are specifying the location of the Wasm file, the import name of the Wasm file, some logging housekeeping, and the mounted binary reference with the command-line call information. ### Remote Service Creation ```bash cargo new curl_adapter cd curl_adapter # copy the above rust code into src/main # copy the specified dependencies into Cargo.toml # copy the above service configuration into Config.toml marine build --release ``` You should have the Fluence module cur-service.wasm in `target/wasm32-wasi/release` . We can test our service with `mrepl`. ### Service Testing Running the REPL, we use the `interface` command to list all available interfaces and the `call` command to run a method. For our purposes, we furnish the [https://duckduckgo.com/?q=Fluence+Labs](https://duckduckgo.com/?q=Fluence+Labs) url to give the the curl adapter a workout. ```bash mrepl Config.toml Welcome to the Marine REPL (version 0.9.1) Minimal supported versions sdk: 0.6.0 interface-types: 0.20.0 app service was created with service id = ee63d3ae-304a-42bb-9a2d-4a4dc056a68b elapsed time 76.5175ms 1> interface Loaded modules interface: curl_adapter: fn download(url: string) -> string 2> call curl_adapter download ["https://duckduckgo.com/?q=Fluence+Labs"] result: String("Fluence Labs at DuckDuckGo
") elapsed time: 356.953459ms 3> ```