0

I am building a server using rust and I have two endpoints exposed health_check and subscriptions, the former has a GET request handler and the later has POST request handler

pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
    let server = HttpServer::new(|| {
        App::new()
            .route("/health_check", web::get().to(health_check))
            .route("/subscriptions", web::post().to(subscribe))
    })
        .listen(listener)?
        .run();
    Ok(server)
}

When I run a curl get request at the health_check endpoint i get a 200 OK response as desired but when I run a curl post request at the subscriptions endpoint curl -d "name=le%20guin&email=ursula_le_guin%40gmail.com" http://127.0.0.1:8000/subscriptions I get an error

Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'http://127.0.0.1:8000/subscriptions'.
At line:1 char:1
+ curl -d "name=le%20guin&email=ursula_le_guin%40gmail.com"   http://12 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

I think there is something wrong with this command, i checked on google and some articles say to add -X POST option in the command but that too doesnt seem to work

cafce25
  • 15,907
  • 4
  • 25
  • 31

0 Answers0