mirror of
https://github.com/fluencelabs/fluid
synced 2025-08-01 04:32:00 +00:00
step1 script
This commit is contained in:
@@ -7,7 +7,7 @@ pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "action")]
|
||||
pub enum Request {
|
||||
Post { msg: String, handle: String },
|
||||
Post { message: String, handle: String },
|
||||
Fetch { handle: Option<String> },
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ fn init() {
|
||||
fn run(arg: String) -> String {
|
||||
// Parse and handle JSON request
|
||||
let result = api::parse(arg).and_then(|request| match request {
|
||||
Request::Post { msg, handle } => add_post(msg, handle),
|
||||
Request::Post { message, handle } => add_post(message, handle),
|
||||
Request::Fetch { handle } => fetch_posts(handle),
|
||||
});
|
||||
|
||||
|
@@ -8,17 +8,22 @@ mkdir -p wasm
|
||||
echo "Building..."
|
||||
cargo +nightly build --target wasm32-unknown-unknown --release >/dev/null
|
||||
cp target/wasm32-unknown-unknown/release/*.wasm ./wasm/
|
||||
echo
|
||||
|
||||
# Run it all on 30000 port with default Fluence API
|
||||
echo "Running..."
|
||||
docker rm -f frun &>/dev/null || true
|
||||
echo 'docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest'
|
||||
docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest >/dev/null
|
||||
echo
|
||||
|
||||
# Wait for app to be initialized
|
||||
sleep 1 && (docker logs -f frun 2>&1 &) | grep -q initialized && sleep 1
|
||||
|
||||
# Send our username to the application
|
||||
echo -e "Sending request...\n"
|
||||
echo -e "Sending request..."
|
||||
echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'$USER --compressed"
|
||||
echo
|
||||
|
||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$USER" --compressed | jq -r .result.data | base64 -D)
|
||||
|
||||
|
40
rust-workshop/step1-json-api/run.sh
Executable file
40
rust-workshop/step1-json-api/run.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p wasm
|
||||
|
||||
# Build fluid WASM module
|
||||
echo "Building..."
|
||||
cargo +nightly build --target wasm32-unknown-unknown --release >/dev/null
|
||||
cp target/wasm32-unknown-unknown/release/*.wasm ./wasm/
|
||||
echo
|
||||
|
||||
# Run it all on 30000 port with default Fluence API
|
||||
echo "Running..."
|
||||
docker rm -f frun &>/dev/null || true
|
||||
echo 'docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest'
|
||||
docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest >/dev/null
|
||||
echo
|
||||
|
||||
# Wait for app to be initialized
|
||||
sleep 1 && (docker logs -f frun 2>&1 &) | grep -q initialized && sleep 1
|
||||
|
||||
# Send our username to the application
|
||||
echo -e "Sending request..."
|
||||
|
||||
# Assign json to a variable using heredoc technique
|
||||
JSON=$(cat <<JSON
|
||||
{"action":"Post","message":"I'm nice, you're nice, it's nice!","handle":"Random Joe"}
|
||||
JSON
|
||||
)
|
||||
|
||||
# Send json as a request, and receive result
|
||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D)
|
||||
|
||||
# Parse result as JSON and print to console
|
||||
echo -e "$RESPONSE" | jq .
|
||||
|
||||
# Remove frun container
|
||||
echo -e "Stopping..."
|
||||
docker rm -f frun >/dev/null
|
@@ -7,7 +7,7 @@ pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "action")]
|
||||
pub enum Request {
|
||||
Post { msg: String, handle: String },
|
||||
Post { message: String, handle: String },
|
||||
Fetch { handle: Option<String> },
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ fn init() {
|
||||
fn run(arg: String) -> String {
|
||||
// Parse and handle JSON request
|
||||
let result = api::parse(arg).and_then(|request| match request {
|
||||
Request::Post { msg, handle } => add_post(msg, handle),
|
||||
Request::Post { message, handle } => add_post(message, handle),
|
||||
Request::Fetch { handle } => fetch_posts(handle),
|
||||
});
|
||||
|
||||
|
@@ -1,8 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::api::AppResult;
|
||||
use crate::database;
|
||||
use crate::errors::err_msg;
|
||||
use log;
|
||||
|
||||
pub fn create_scheme() -> AppResult<()> {
|
||||
|
@@ -7,7 +7,7 @@ pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "action")]
|
||||
pub enum Request {
|
||||
Post { msg: String, handle: String },
|
||||
Post { message: String, handle: String },
|
||||
Fetch { handle: Option<String> },
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ fn init() {
|
||||
fn run(arg: String) -> String {
|
||||
// Parse and handle JSON request
|
||||
let result = api::parse(arg).and_then(|request| match request {
|
||||
Request::Post { msg, handle } => add_post(msg, handle),
|
||||
Request::Post { message, handle } => add_post(message, handle),
|
||||
Request::Fetch { handle } => fetch_posts(handle),
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user