Search code examples
javascriptc++httprestbed

Getting HTTP 501 Not Implemented when there is definitely an implementation?


I'm attempting to make a simple http service, I've got GET and POST working so far. For some reason though every time I try to send a PUT, my restbed server returns 501, even though I have the method handler set for PUT.

The PUT, POST, and GET methods are set the exact same way, via resource->set_method_handler("METHOD", METHOD_method_handler);

The handler / setup

void put_method_handler(const std::shared_ptr<restbed::Session>& session) {
  const auto request = session->get_request();

  std::cout << "yes\n";
}

int main() {
  auto resource = std::make_shared<restbed::Resource>();
  resource->set_path("/resource");
  resource->set_method_handler("PUT", put_method_handler);

  // bla bla service.publish() etc
}

Currently using a simple javascript FETCH via the chrome console to just see if it's recieving anything.

fetch("http://localhost:1234/resource", {method: 'PUT', body: {}})

My server should be printing the cout statement, but instead it is silent and the fetch returns 501.


Solution

  • Problem ended up being that our restbed implementation had broken. Don't know the cause of that, but removing it and redownloading worked.