GitBook: [docs] 54 pages and 17 assets modified

This commit is contained in:
boneyard93501
2021-03-29 02:17:52 +00:00
committed by gitbook-bot
parent c6a1b1204a
commit 818e9f6253
71 changed files with 3830 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# Recipes

View File

@@ -0,0 +1,4 @@
# Data Replication
Coming soon. If you really need this section, contact us through any of the social media channels or Github.

View File

@@ -0,0 +1,4 @@
# Error Management and Testing Of Services
Coming soon. If you really need this section, contact us through any of the social media channels or Github.

4
recipes_recipes/ipfs.md Normal file
View File

@@ -0,0 +1,4 @@
# IPFS
Coming soon. If you really need this section, contact us through any of the social media channels or Github.

View File

@@ -0,0 +1,4 @@
# Local Filesystem
Coming soon. If you really need this section, contact us through any of the social media channels or Github.

View File

@@ -0,0 +1,104 @@
# Curl
## 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/fce/tree/master/examples/url-downloader/curl_adapter) illustrates the implementation requirement.
```rust
use fluence::fce;
use fluence::WasmLoggerBuilder;
use fluence::MountedBinaryResult;
pub fn main() {
WasmLoggerBuilder::new().build().unwrap();
}
#[fce]
pub fn download(url: String) -> String {
log::info!("get called with url {}", url);
let result = unsafe { curl(vec![url]) };
String::from_utf8(result.stdout).unwrap()
}
#[fce]
#[link(wasm_import_module = "host")]
extern "C" {
fn curl(cmd: Vec<String>) -> MountedBinaryResult;
}
```
with the following dependencies necessary in the Cargo.toml:
```rust
fluence = { version = "=0.4.2", 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 FCE interface called download.
### Code References
[Mounted binaries](https://github.com/fluencelabs/fce/blob/c559f3f2266b924398c203a45863ebf2fb9252ec/fluence-faas/src/host_imports/mounted_binaries.rs)
### Service Construction
In order to create a valid Fluence service, a service configuration is required.
```text
modules_dir = "target/wasm32-wasi/release"
[[module]]
name = "curl_adapter"
logger_enabled = true
[mounted.mounted_binaries]
curl = "/usr/bin/curl"
```
We are specifying the location of the Wsasm file, the import name of the Wasm file, some logging housekeeping, and the mounted binary reference with the command-line call information.
### Service Creation
```bash
cargo new curl-service
cd curl-service
# copy the above rust code into src/main
# copy the specified dependencies into Cargo.toml
# copy the above service configuration into Config.toml
fce build --release
```
You should have the Fluence module curl\_adapter.wasm in `target/wasm32-wasi/release` we can stest our service with `fce-repl`.
### Service Test
Running the REPL, we use the `interface` command to list all available interfaces and the `call` command to run a method. Fr 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
fce-repl Config.toml
Welcome to the FCE REPL (version 0.5.2)
app service was created with service id = 8ad81c3a-8c5c-4730-80d1-c54cd177725d
elapsed time 40.312376ms
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("<!DOCTYPE html><html lang=\"en-US\" class=\"no-js has-zcm no-theme\"><head><meta name=\"description\" content=\"DuckDuckGo. Privacy, Simplified.\"><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"><title>Fluence Labs at DuckDuckGo</title><link rel=\"stylesheet\" href=\"/s1963.css\" type=\"text/css\"><link rel=\"stylesheet\" href=\"/r1963.css\" type=\"text/css\"><meta name=\"robots\" content=\"noindex,nofollow\"><meta name=\"referrer\" content=\"origin\"><meta name=\"apple-mobile-web-app-title\" content=\"Fluence Labs\"><link rel=\"preconnect\" href=\"https://links.duckduckgo.com\"><link rel=\"preload\" href=\"/font/ProximaNova-Reg-webfont.woff2\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" /><link rel=\"preload\" href=\"/font/ProximaNova-Sbold-webfont.woff2\" as=\"font\" type=\"font/woff2\" crossorigin=\"anonymous\" /><link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\" /><link id=\"icon60\" rel=\"apple-touch-icon\" href=\"/assets/icons/meta/DDG-iOS-icon_60x60.png?v=2\"/><link id=\"icon76\" rel=\"apple-touch-icon\" sizes=\"76x76\" href=\"/assets/icons/meta/DDG-iOS-icon_76x76.png?v=2\"/><link id=\"icon120\" rel=\"apple-touch-icon\" sizes=\"120x120\" href=\"/assets/icons/meta/DDG-iOS-icon_120x120.png?v=2\"/><link id=\"icon152\" rel=\"apple-touch-icon\"s
<snip>
ript\">DDG.index = DDG.index || {}; DDG.index.signalSummary = \"\";</script>")
elapsed time: 334.545388ms
3>
```

View File

@@ -0,0 +1,51 @@
# Setting Up Your Environment
In order to develop within the Fluence solution, [Rust](https://www.rust-lang.org/tools/install) and small number of tools are required.
## Rust
Install Rust:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
once Rust is installed, we need to expand the toolchain and include [nightly build](https://rust-lang.github.io/rustup/concepts/channels.html) and the [Wasm](https://doc.rust-lang.org/stable/nightly-rustc/rustc_target/spec/wasm32_wasi/index.html) compile target.
```bash
rustup install nightly
rustup target add wasm32-wasi
```
To keep Rust and the toolchains updated:
```bash
rustup self update
rustup update
```
There are a number of good Rust installation and IDE integration tutorials available. [DuckDuckGo](https://duckduckgo.com/) is your friend but if that's too much effort, have a look at [koderhq](https://www.koderhq.com/tutorial/rust/environment-setup/).
## Fluence Tools
Fluence provides several tools to support developers. Fluence cli, `flcli`, facilitates the compilation of modules to the necessary wasm32-wasi target. Fluence REPL, `fce-repl`, on the other hand, is a cli tool to test and experiment with FCE modules and services locally.
```bash
cargo install fcli
cargo +nightly install frepl
```
In addition, Fluence provides the [proto-distributor](https://github.com/fluencelabs/proto-distributor) tool, aka `fldist`, for service lifecyle management. From deploying services to the network to executing AIR scripts, `fldist` does it all.
```bash
npm install -g @fluencelabs/fldist
```
## Fluence SDK
For frontend development, the Fluence [JS-SDK](https://github.com/fluencelabs/fluence-js) is currently the favored, and only, tool.
```bash
npm install @fluencelabs/fluence
```

4
recipes_recipes/redis.md Normal file
View File

@@ -0,0 +1,4 @@
# Redis
Coming soon. If you really need this section, contact us through any of the social media channels or Github.

View File

@@ -0,0 +1,4 @@
# Sqlite
Coming soon. If you really need this section, contact us through any of the social media channels or Github.