Coder Social home page Coder Social logo

autobindle's People

Contributors

itowlson avatar radu-matei avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

autobindle's Issues

Work with multiple endpoints

Hello, I 'm currently testing spin with rust to develop a simple API REST. I searched in the documentation but i didn't find a way to used multiple endpoint's inside the same .rs. This work can be done by using multiple .rs of course, but I'm wondering if it's possible to define it without using a match.

My current work is like this:

fn hello(req: Request) -> Result {
println!("{:?}", req.headers());
match req.method() {
&Method::POST => {
Ok(http::Response::builder()
.status(200)
//.header("foo", "bar")
.body(Some("POST!\n".into()))?)
}
&Method::GET => {
Ok(http::Response::builder()
.status(200)
//.header("foo", "bar")
.body(Some("GET!\n".into()))?)
}
&Method::DELETE => {
Ok(http::Response::builder()
.status(200)
//.header("foo", "bar")
.body(Some("DELETE!\n".into()))?)
}
}

Ok(bad_request())

}

fn bad_request() -> Response {
http::Response::builder().status(400).into()
}

But what I want is something like this:

#[http_component]
fn hello_get(req: Request) -> Result {
println!("{:?}", req.headers());
Ok(http::Response::builder()
.status(200)
//.header("foo", "bar")
.body(Some("GET!\n".into()))?)
}

#[http_component]
fn hello_post(req: Request) -> Result {
println!("{:?}", req.headers());
Ok(http::Response::builder()
.status(200)
//.header("foo", "bar")
.body(Some("POST!\n".into()))?)
}

#[http_component]
fn hello_delete(req: Request) -> Result {
println!("{:?}", req.headers());
Ok(http::Response::builder()
.status(200)
//.header("foo", "bar")
.body(Some("DELETE!\n".into()))?)
}

Is this possible? How can I do it?

Bindle server error (1)

I get the following error trying to start Bindle in a new environment:

[2022-02-23 10:10:50.516] [exthost] [error] Canceled: Canceled
    at Object.F [as canceled] (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:5:1172)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:97:9076
    at Array.forEach (<anonymous>)
    at i.dispose (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:97:9024)
    at p.terminate (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:102:694)
    at s (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:112:36409)
    at Socket.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:112:34061)
    at Socket.emit (events.js:327:22)
    at Pipe.<anonymous> (net.js:673:12) autobindle.stop {"value":"fermyon.autobindle","_lower":"fermyon.autobindle"}

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.