Giter VIP home page Giter VIP logo

thangchung / dapr-labs Goto Github PK

View Code? Open in Web Editor NEW
42.0 2.0 4.0 10.54 MB

Many forms of coffeeshop implemented by C# and Rust run on WebAssembly/WASI (Spin) + Dapr. ⭐️ Star to support our work!

Home Page: https://github.com/thangchung/dapr-labs

License: MIT License

Shell 0.86% HCL 5.22% C# 69.40% Dockerfile 2.55% Rust 21.13% Makefile 0.84%
consul consul-connect dapr devcontainer dotnet nomad terraform rust spin wasi

dapr-labs's Introduction

dapr-labs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dapr-labs's Issues

WASM Component Model

CoffeeShop on Spin with Dapr

Refs: https://www.thorsten-hans.com/how-to-blog-backends-with-spin-and-fermyon-cloud/

#[http_component]
fn handle_blog_apis_rust(req: Request) -> Result<Response> {
  let mut router = spin_sdk::http::Router::default();
  router.post("/contact", requests::process_contact_request);
  router.post("/sponsor", requests::process_sponsor_request);
  router.post("/subscriptions", newsletter::subscribe);
  router.get("/search", search::search);
  router.add("/...", http::Method::OPTIONS, cors::process_preflight);
  router.handle(req)
}
pub(crate) fn search(req: Request, _params: Params) -> Result<Response>{
  println!("[SEARCH]: Endpoint invoked");
  let Some(search_term) = get_query_string_parameter(req.uri(), "query") else {
    println!("[Error]: Could not find search term");
    return Ok(http::Response::builder()
      .status(http::StatusCode::BAD_REQUEST)
      .body(None)?);
  };
  println!("[SEARCH]: Endpoint invoked with '{}'", &search_term);

  let Ok(search_url) = config::get(CFG_NAME_SEARCH_URL) else {
    println!("[Error]: Could not find Azure Search Service URL");
    return Ok(http::Response::builder()
      .status(http::StatusCode::INTERNAL_SERVER_ERROR)
      .body(None)?);
  };

  let Ok(search_api_key) = config::get(CFG_NAME_SEARCH_API_TOKEN) else {
    println!("[Error]: Could not find Azure Search API Key");
    return Ok(http::Response::builder()
      .status(http::StatusCode::INTERNAL_SERVER_ERROR)
      .body(None)?);
  };

  let query_string = build_azure_search_query_string(search_term.as_str());
   
   
  let req = http::Request::builder()
    .method(http::Method::GET)
    .header(http::header::ACCEPT, "application/json")
    .header(http::header::CONTENT_TYPE, "application/json")
    .header("api-key", search_api_key)
    .uri(format!("{}{}", search_url, query_string))
    .body(None)?;

  match spin_sdk::outbound_http::send_request(req) {
    Ok(r) => {
      println!("[SEARCH]: Will respond with search results");
      Ok(builder_with_cors(r.status())
      .body(r.body().clone())?)
    },
    Err(e) => {
      println!("[Error]: Did not receive successful response from Azure Search Service ({})", e);
      Ok(http::Response::builder()
      .status(http::StatusCode::INTERNAL_SERVER_ERROR)
      .body(None)?)
    },
  }
}

Problem with devcontainer.json

devcontainer.json does not build in JetBrains IDE 2024.1 and VSCode.

JetBrains IDE Welcome screen -> DevContainers -> New DevContainer (from VCS Project, Docker must be installed.) Insert the git@ link of the repository with devcontainer.json. -> "Build container and Continue"
image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.