Good day,
I am currently experimenting with the pyRevit Routes module, by building a web front end to access the Revit entities database, like doors, windows etc.
I would like to know if it is possible to change “Content-Type” header of the response from “application/json” to “text/html”?
Or where in the code i can allow for this.
Even though I set the “Content-Type” header to “text/html”, the response is “application/json”.
I would like to try an build the Routes API with HTMX frontend library, so I would need the response “Content-Type” header to be “text/html”, but somehow I am not able to change “Content-Type” the headers.
As far as i understand the code, it calls the json.dump() function on the outgoing data. Based on the python json.dump() documentation it says “Serialize obj to a JSON formatted str using this conversion table. The arguments have the same meaning as in dump().”, which means it’s Serializing the data.
Instead i want to return html data as raw text/htm not as json serialized.
When i call the parse_response() function, i set the headers based on what “Content-type” i want to send.
But json.dump() function is changing the data format to a json string.
You’re right that json.dumps serializes the data, but the serialization of a string is the string itself.
So you just need to return "<html><body><div>..." or whatever you want to output.
Now that I think of it, that json.dumps instruction is useless, it should just be data = response
Exactly!
So when using htmx I can send bits of html code from the server to the client. And the htmx javascript library will place the code where it is required.
To be clear, what I meant is that the instruction does nothing, and it should he modified with a PR (feel free to create one! ), but it is perfectly usable as it is because it just passes the string as it is.