question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support simple class with BodySerializationMethod.UrlEncoded

See original GitHub issue

The param is required to implement IDictionary, https://github.com/canton7/RestEase#url-encoded-bodies e.g.

Task Collect([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> data);

Refit can do this, see: https://github.com/paulcbetts/refit#form-posts e.g.

Task Collect([Body(BodySerializationMethod.UrlEncoded)] Measurement measurement);
// Serialized as: v=1&tid=UA-1234-5&cid=d1e9ea6b-2e8b-4699-93e0-0bcbd26c206c&t=event

Are there any reasons why RestEase doesn’t support this or is this just not implemented yet?

Nevertheless, this is an awesome lib! Keep up the good work!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
canton7commented, Feb 4, 2018

Todo list:

  1. Write code to serialise an object to a set of query params.
  2. Add a new attribute allowing a name to be given to a property in such a class
  3. Add a new type of serialiser allowing this behaviour to be customised. Move the existing dictionary serializarion code into this serialiser. Make sure we allow custom cultures, etc.
  4. Refractor RequestInfo so that QueryMap can accept any object, and pass that object to the Requester.
  5. Update Requester so that it calls the serialiser for QueryMap and serialised request bodies.
  6. Consider whether to allow a format string to be used when serializinf property values.
  7. Consider what to do with nested objects. Do we just call ToString on them, or do we try and serialise them? Changing this later will be breaking behaviour.
  8. Tests. Cover non-public properties, abstract, no getter, getter throws an exception, getter returns a collection, getter returns null, getter returns an object whose ToString method throws. Nested objects if appropriate.
  9. Document it all.
1reaction
canton7commented, Jan 27, 2018

It’s not supported because I didn’t want to start going down the rabbit hole of writing a custom serializer! Those things get complex fast: I’ve done it before.

That said, it probably isn’t too hard to let json.net turn the object into a JObject, then munge that into a query string. I’ll have an investigate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I serialize my class to send it as urlencoded with refit
This answer might have come very late. But recently I was working on a similar use case. And the below code worked for...
Read more >
Support simple class with BodySerializationMethod. ...
Support simple class with BodySerializationMethod.UrlEncoded.
Read more >
Refit | The automatic type-safe REST library for Xamarin ...
For APIs that take form posts (i.e. serialized as application/x-www-form-urlencoded ), initialize the Body attribute with BodySerializationMethod.UrlEncoded .
Read more >
Consuming a RESTful Web Service in Xamarin Forms ...
As you can see here, I'm using the common part of the URL (Base API URL) as a parameter in the RestService class...
Read more >
RestEase
Easy -to-use typesafe REST API client library for .NET Standard 1.1 and .NET Framework 4.5 and higher, which is simple and customisable. Inspired...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found