Snake_case but only for certain requests

I’m building a testing stub web service that hosts multiple API’s that mimic several services like Stripe, Calendly, etc. (let’s say I have 5x different services, each with 10x different service operations).

For some of the services I want to change the default JsConfig to use snake_case (like Stripe) and for others to use PascalCase (like o356), and others camelcase (like Calendly). There are other serialization differences too apart from just the text case.

I know about JsConfig but not sure what the mechanism is to apply different JsConfig for different sets of request DTOs or different services.

What should I be looking at for that capability? Do I have to configure each individual operation? or can I group things together per service?

The Customize JSON Responses docs shows how you can customize the API responses by returning a decorated HttpResult with the Config Scope you want to use, e.g:

return new HttpResult(responseDto) {
    ResultScope = () => 
        JsConfig.With(new Config { TextCase = TextCase.SnakeCase })
};

This is only for serialization, you can’t customize deserialization per request. But Stripe uses HTTP’s curl-friendly QueryString and FormData for Service Requests so you wont need to perform custom deserialization.

You can have all APIs in the same Service class use the same decorated response by using the Intercept Service Requests hooks, e.g:

public class MyStripeServices : Service
{
    public override object OnAfterExecute(object responseDto) => 
        new HttpResult(responseDto) {
            ResultScope = () => 
                JsConfig.With(new Config { TextCase = TextCase.SnakeCase })
        };
}
1 Like

Ah! Lovely, thank you