CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.05k stars 172 forks source link

can't find much on IResponseNegotiator docs or samples #290

Closed drdamour closed 1 year ago

drdamour commented 2 years ago

i'm intrigued by this idea as i think it'll help me return different representations for accept: application/hal+json vs application/vnd.mason+json for example, but i couldn't find much on it. hoping there's some stuff out there i'm missing

jchannon commented 2 years ago

You are correct in your assumption and correct in a lack of samples which will need fixing in the future. For now I can point you to the tests

https://github.com/CarterCommunity/Carter/blob/main/test/Carter.Tests/ContentNegotiation/ResponseNegotiatorTests.cs

On Sun, 26 Dec 2021 at 18:54, drdamour @.***> wrote:

i'm intrigued by this idea as i think it'll help me return different representations for accept: application/hal+json vs application/vnd.mason+json for example, but i couldn't find much on it. hoping there's some stuff out there i'm missing

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/290, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJRKB3LA5ALBWMNNJGDUS5QERANCNFSM5KZFWUQQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

drdamour commented 1 year ago

@jchannon did samples get added somewhere?

jchannon commented 1 year ago

No, I think the tests are pretty clear

drdamour commented 1 year ago

hm, not to be flippant, but based on what? have people successfully created em from the tests?

JoeStead commented 1 year ago

There's some usage in the tests here: https://github.com/CarterCommunity/Carter/blob/main/test/Carter.Tests/ContentNegotiation/ResponseNegotiatorTests.cs#L113-L160

Without a more specific request for what you'd like to know about it this would be impossible to give you something you're satisfied with.

jchannon commented 1 year ago

Well you just create a class and implement the interface that has 2 methods. Here's an example:

https://github.com/CarterCommunity/Carter/blob/main/test/Carter.Tests/ContentNegotiation/ResponseNegotiatorTests.cs#L113

It says this negotiator will be used when the accept header is foo/bar and then in the Handle method it's up to you how you write the response.