Skip to content

Document POST body example #978

Closed

Description

@wulftone

After a bunch of experimentation, I figured out that you can use a POJO as a POST body, but I couldn't find it anywhere in the documentation. e.g. You can do

public interface Boop {
    @RequestLine("POST /boop/{someParam}")
    @Headers({
        "Accept: application/json",
        "Content-Type: application/json"
    })
    BoopResponse createBoopUsingPOST(Boop boop, @Param("someParam") String someParam);

    class Boop {
        public String value;
    }
}

But the tricky part is that the POJO param (boop, in the example), must come first in the parameter list of the method. That was difficult to find out!

Activity

  1. kdavisk6 commented on May 23, 2019

    @kdavisk6
    Member

    @wulftone

    Thanks for this example. It is missing from the documentation. You can define the body of the request two ways:

    • annotating the parameter with @Body
    • the first method parameter without an annotation is assumed to be the Body

    We should update the documentation to explain this and add you example.

  2. eiselems commented on Jun 10, 2019

    @eiselems
    Contributor

    @wulftone @kdavisk6 is this like you had it in mind?

  3. wulftone commented on Jun 10, 2019

    @wulftone
    Author

    Pretty much, I commented on the pr: #986 (comment)

  4. eiselems commented on Jun 11, 2019

    @eiselems
    Contributor

    @wulftone is it really failing for you when you put the boop parameter in any other position?
    I updated the github-example in the repository and it seems to work in all positions.

  5. wulftone commented on Jun 12, 2019

    @wulftone
    Author

    Yes, let me verify exactly why and get back to you... It is interesting that you found it doesn't matter in the example

  6. added a commit that references this issue on Jun 18, 2019
    0ed5008
  7. added a commit that references this issue on Jun 30, 2019
    b180bf0
  8. sleroy commented on Jun 3, 2020

    @sleroy

    Indeed I lost 10 minutes to find an Example. Could not guess it easily from the readme...

  9. eiselems commented on Jun 4, 2020

    @eiselems
    Contributor

    @sleroy hoped the example would be sufficient

      @RequestLine("POST /repos/{owner}/{repo}/issues")
      void createIssue(Issue issue, @Param("owner") String owner, @Param("repo") String repo);
    
    

    How should we improve it?

  10. added 2 commits that reference this issue on Oct 7, 2024
    f18e001
    b0840d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationIssues that require updates to our documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions