richardszalay/mockhttp

Helper to read JSON file as response

diegodrf opened this issue · 2 comments

I need to deal with huge JSON responses on my project, so to keep everything organized and easy to maintain I keep them in .json files.

I created a simple function to read this JSON and pass it as a string to the .Respond().

It would be nice if the package did the hard work for me accepting a file path and I simply pass the mime type application/json or text/plain to generate the expected response.

Is It could be a new feature? Or do you suggest an existing method to help me with this scenario?

Not something I'd likely add to the library, but it should be easy enough to create a RespondJsonFile extension method that in turn calls Respond with ByteArrayContent

Thank you for the answer.

I will follow your suggestion to create an extension method.

I explored the source code and found a method to deal with streams. It will optimize the implementation that I already have.

In the current implementation, I'm reading the file as a string to pass it to Respond().