Covertness / coap-rs

A Constrained Application Protocol(CoAP) library implemented in Rust.
MIT License
209 stars 48 forks source link

No easy way to set options in client requests #89

Closed doxxx closed 7 months ago

doxxx commented 7 months ago

Using CoAPClient, there is no way to set options in a request. It's possible to do so by constructing a CoapRequest manually, but to do so requires re-implementing a bunch of functionality already present in CoAPClient (gen_message_id, request_path_with_timeout and parse_coap_url in particular).

Covertness commented 7 months ago

Which option do you want to set ? Coap has many options, each of them has its own special role. I think generic set function won't be very useful. I would like to implement a specific function if you have a common scenario.

doxxx commented 7 months ago

The ones I'm interested in are the Accept and Content-Format options.

doxxx commented 7 months ago

If the CoAPClient interface is getting too complex, a request builder may be something to explore.

osobiehl commented 7 months ago

I'm down to rework part of the client and expose a low-level perform_request_through_transport method to replace request_path_with_timeout as the lowest-level method to allow you to customize whatever you want on the request. Honestly a Builder isn't something I see in scope because we just use coap-lite.

If you're willing to be a little bit patient I can do the change after the DTLS support PR.

doxxx commented 7 months ago

Right now it's a nice to have. I couldn't find a CLI CoAP client, so I wrote my own. When I was contemplating the features it should include, one of the main ones that occurred to me was content-type support. However, I don't need content-type support for my own purposes yet.

Covertness commented 7 months ago

Closed. Reopen it if you have any new problem about it.

doxxx commented 7 months ago

Thanks, I was able to rework my CLI tool to use the latest git version of coap-rs.

For those who may be interested: Instead of going the full builder route, I implemented a helper extension trait to make it easier to set some options on a request: https://bitbucket.org/gordon_tyler/workspace/snippets/XEB45a

doxxx commented 7 months ago

Although, a similar situation has cropped up with observe and observe_with_timeout -- there's no way to set options on the request without re-implementing those rather non-trivial functions myself.