Skip to content

Alter json body in POST request #205

Answered by canton7
eNTi asked this question in Q&A
Nov 12, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

You have two options:

  1. Create an e.g. Request<T> type which wraps each body you send, e.g:
public class Request<T>
{
    [JsonProperty("req")]
    public T Body { get; set; }

    public Request(T body) => Body = body;
}

[Post(...)]
public void PostAsync([Body] Request<SomeBody> body);
  1. Write your own RequestBodySerializer which wraps the serialized body in the containing object. See that link for more details -- it will look like this, but wrapped in an extra JSON object.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@eNTi
Comment options

@eNTi
Comment options

@canton7
Comment options

@eNTi
Comment options

Answer selected by eNTi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants