Reputation: 536
I have a project written in Rocket with the endpoint /foo
that returns data in application/json
. I'm using rocket, rocket_codegen, serde, and serde_json.
#[get("/foo")]
fn foo() -> Json {
Json(json!({
"foo": 1
}))
}
This works nicely, but I need to respond with application/hal+json
so I guess I need to write my own response, and I have failed. How do I return my JSON with the Content-Type application/hal+json
?
Upvotes: 1
Views: 658
Reputation: 536
I got some help over at the projects chat and the solution was:
#[get("/foo")]
fn foo() -> Content<Json> {
let r = json!({
"foo": 1
})
Content(ContentType::new("application", "hal+json"), Json(r))
}
Upvotes: 1