Skullabs / kikaha

A fast middleware designed for microservices
https://skullabs.github.io/kikaha/
Apache License 2.0
59 stars 13 forks source link

Easier way to get raw input #265

Closed roneigebert closed 5 years ago

roneigebert commented 5 years ago

I need to have a @POST and get the body contents without any seralization. The only way to do this is creating a @WebResource class manually, but I think we need have a easier way like that (pseudo code):

@POST postMethod( @RawInput byte[] input ){ /** code */  }
// or
@POST postMethod( @RawInput InputStream input ){ /** code */  }
// or
@POST postMethod( @RawInput String input ){ /** code */  }

Obs: I know how to create a @WebResource manually to solve my problem, but, other users I think not

miere commented 5 years ago

Hey @roneigebert ,

That's actually a pretty good idea. I think that if you include the following snippet here you will probably allow any developer to receive byte[] in the routing method.

.and( typeIs( byte[].class ), v -> "bodyData" )

Do you want to give it a try?

roneigebert commented 5 years ago

Hi @miere.

I liked your suggestion, it's easier than create an annotation, but if I do this, the user won't be able to use "byte[].class" to transfer data as JSON format (or any other format).

What I can do without creating any annotation is changing the parameter parser to check if the parameter an InputStream, something like that:

.and( typeIs( InputStream.class ), v -> new ByteArrayInputStream( {byteArrayHere} ) )

Do you like it? If you agree I will send a PR soon ;)

miere commented 5 years ago

Sure, mate. I'll be waiting for you PR. ;) Cheers

On Mon, Aug 26, 2019 at 1:22 PM Ronei notifications@github.com wrote:

Hi @miere https://github.com/miere.

I liked your suggestion, it's easier than create an annotation, but if I do this, the user won't be able to use "byte[].class" to transfer data as JSON format (or any other format).

What I can do without creating any annotation is changing the parameter parser to check if the parameter an InputStream, something like that:

.and( typeIs( InputStream.class ), v -> new ByteArrayInputStream( {byteArrayHere} ) )

Do you like it? If you agree I will send a PR soon ;)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Skullabs/kikaha/issues/265?email_source=notifications&email_token=AAD7NUA7WQQKIW6CUB4LW7LQGNEAXA5CNFSM4HLBMLSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5DEZVQ#issuecomment-524700886, or mute the thread https://github.com/notifications/unsubscribe-auth/AAD7NUDIKKOVL5ATDH6YPLLQGNEAXANCNFSM4HLBMLSA .

-- / Miere L. Teixeira /