Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Conversation

@bmoyles0117
Copy link
Contributor

@bmoyles0117 bmoyles0117 commented Mar 28, 2018

This was introduced in #78.

LOG(WARNING) << "No matching resource for " << id;
}
std::map<std::string, std::string> headers = {
{"Content-Type", "text/plain"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've chosen to use text/plain here as we're not actually returning JSON. If we decide we'd like to return an empty object, we can update this accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Should we also write "Not found\n" into the response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I believe that rest APIs should always return JSON, so I would vote for something like {"error:"Not found"}, but I'm not sure that would play well with our current design. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I've found some examples that also add "code":404. I'm happy with either one -- we are, in effect, designing this API. Let's do it!

};

conn->set_status(HttpServer::connection::ok);
conn->set_headers(headers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the following work:

      conn->set_headers({
        {"Content-Type", "application/json"},
      });

? Also below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've inlined it, using the syntax the way you had it resulted in the error below. Is this a happy medium?

api_server.cc:53:8: error: no matching function for call to 'boost::network::http::async_connection<boost::network::http::tags::http_server, google::MetadataApiServer::Handler>::set_headers(<brace-enclosed initializer list>)'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, wrapping it into an std::map temporary is exactly the right fix for that. Sorry I didn't check this before suggesting.

LOG(WARNING) << "No matching resource for " << id;
}
std::map<std::string, std::string> headers = {
{"Content-Type", "text/plain"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Should we also write "Not found\n" into the response?

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Igor's comments. Otherwise LGTM

};

conn->set_status(HttpServer::connection::ok);
conn->set_headers(headers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, wrapping it into an std::map temporary is exactly the right fix for that. Sorry I didn't check this before suggesting.

LOG(WARNING) << "No matching resource for " << id;
}
std::map<std::string, std::string> headers = {
{"Content-Type", "text/plain"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I've found some examples that also add "code":404. I'm happy with either one -- we are, in effect, designing this API. Let's do it!

{"Content-Type", "text/plain"},
}));
json::value json_response = json::object({
{"status_code", json::int(404)},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a json::int. Did you mean json::number?

}
conn->set_status(HttpServer::connection::not_found);
conn->set_headers(std::map<std::string, std::string>({
{"Content-Type", "text/plain"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true, right?

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@bmoyles0117 bmoyles0117 merged commit d6b87e6 into master Mar 29, 2018
@bmoyles0117 bmoyles0117 deleted the bmoyles0117-fix-monitored-resource-status-code branch March 29, 2018 17:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants