ThorstenHans / blog-comments

0 stars 0 forks source link

first-glance-at-spin-router-for-rust/ #6

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

A First Glance at the Spin Router for Rust · Thorsten Hans' blog

With Fermyon Spin 1.1, Spin SDKs for Rust and GoLang come built-in routers for HTTP apps. This article demonstrates how to use the new router in Rust to layout a full-fledged HTTP API.

https://www.thorsten-hans.com/first-glance-at-spin-router-for-rust/

pklewing commented 1 year ago

Thanks for this cool blog post!

Just had to perform the following 2 minor steps to make it work as expected in my own environment:

  1. Also execute cargo add uuid -F v4 when initializing the Spin application, as you use uuid::Uuid in the create handler. This dependency is included in the Cargo.toml file in your repository, but I used the vanilla template Cargo.toml file that was generated by the spin new --accept-defaults http-rust book_api command.

  2. Add the line key_value_stores = ["default"] to the [[component]] section of the generated spin.toml file. You mention this in your detailed guide on how to use the built-in key-value store that you already refer to here, but of course I initially forgot to include it.

Running spin build --up directly from a git clone of your repository works fine without any changes, so this was just due to the fact that I was following your guidelines along step by step.

Keep up the good work!

pklewing commented 1 year ago

Just another (minor) glitch in the inline curl test client code above:

# create a new book
id=$(curl -sXPOST \
  --json '{"title": "The art of Wasm", "author": "John Doe", "category":"Programming", "year": 2023 }' \
  http://localhost:3000) | jq -r ".id"

should be

# create a new book
id=$(curl -sXPOST \
  --json '{"title": "The art of Wasm", "author": "John Doe", "category":"Programming", "year": 2023 }' \
  http://localhost:3000 | jq -r ".id")

So, you have to move the closing bracket to the end of the complete piped command statement so that only the JSON return value of ".id" will be captured into the local variable ìd`.

ThorstenHans commented 1 year ago

Thanks for the immersive feedback @pklewing ❤️ I'll bake it into the post.

ThorstenHans commented 1 year ago

@pklewing took a while but finally updated the article. Thanks once again 👍🏻