Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XML as response type #575

Open
Muhomorik opened this issue Jan 2, 2023 · 0 comments
Open

Add XML as response type #575

Muhomorik opened this issue Jan 2, 2023 · 0 comments

Comments

@Muhomorik
Copy link

Muhomorik commented Jan 2, 2023

Is your feature request related to a problem? Please describe.

Version 3.5.2.

I have an old API that returns XML and it gets complicated...

It seems that Response.ContentType always returns json.

I've tried:

Response.ContentType = MimeType.Html Response.ContentType = "text/xml"

I want additional MimeTypes for XML: text/xml, application/xml

Describe the solution you'd like

I would like to skip default serialization when content type is set to anything else that json without using OpenResponseText.
Generally, I would like to return serialized xml string and manually call ToString on XElement.

Better solution is to return XElement or XDocument and let EmbedOI handle serialization and content type like it does with json.

`

<Route(HttpVerbs.Get, "/")>
Public Async Function GetXml() As Task(Of XElement)
	Response.ContentType = MimeType.TextXml

	Dim elementName As String = "contact"
	Dim contact3 As XElement =
			<<%= elementName %>>
				<name>Hohoho</name>
			</>
	
	Return contact3 // XElement or XDocument
	
End Function

`

Describe alternatives you've considered

The only solution that works is (VB):

`

    <Route(HttpVerbs.Get, "/")>
    Public Async Function GetXml() As Task(Of String)
            Response.ContentType = "text/xml"

            Dim elementName As String = "contact"
            Dim contact2 =
                    <contact>
                        <name>Hohoho</name>
                    </contact>
            
            Using writer = HttpContext.OpenResponseText()
                Await writer.WriteAsync(contact2.ToString())
            End Using
    End Function

`

Additional context
Dev tools should show correct output

bild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant