-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to send null through Alamofire PATCH requests #3631
Comments
Using URL encoding for body is pretty rare, which is why this feature wasn't built initially. Are you sure you can't use JSON? In any event, this looks doable, but I'll investigate more later. |
Another question is how to handle |
I've added a |
Looking at it again, it definitely looks like your example output is JSON, not a form encoding. That encoding is up to If that behavior is absolutely required you can use of other alternate JSON encoders that may have that ability. Just make it conform to Alamofire's |
Hey jshier, apologies i was out for a few days. Yes I think you're right, the heart of this problem was that our networking layer on iOS side was restricting everything to URLencoding before getting to Alamofire. We were finally able to detangle it and test out passing to JSONEncoding and that worked as expected. i think your above comment about copying Vapor's behavior is a good one and would make sense. Thanks for working on this and responding so quickly. Did you want me to close this request or did you want to do that? |
I'll do it once I decide whether or not to ship the |
I would like to throw a +1 on this. Not being able to use Has anyone come up with a good workaround for this? I am considering the following:
|
@jmonroe You can use the |
@jshier Thanks, I will look at doing that for now. Thanks for the update. I was hesitating to use the branch without knowing if it was going to move forward or not. |
### Issue Link 🔗 #3631 ### Goals ⚽ This PR adds a `NilEncoding` type for `URLEncodedFormParameterEncoder` so that it can handle optional values. ### Implementation Details 🚧 Like the other encodings, it allows a variety of representations. Unlike the others, it's implemented as a `struct` so it can more easily be used with custom encodings. ### Testing Details 🔍 Tests added for each encoding.
|
Problem
Updating objects on our server with nil values (for instance when you want to null a field in a database) does not work currently with Alamofire. This is an important feature in development espeically when using PATCH endpoints where the absence of a field does not mean that the field is null.
Description and attempted solutions
I have tried a few ways to get this functionality as expected:
I have tried just sending nil values through a dictionary which was suggested to work in this closed issue. However that does not work, as you can see the URLEncodedFormEncoder does not accept nil values
I have also tried to create a property wrapper that encodes nil via jSONEncoder and pass that through to Alamofire. This results in sending "<null>" through the API, which is not the desired result (we just want the null keyowrd, not a string)
Feature Request
Allow requests using the http method PATCH to send the null keyword as a value for parameters.
Value to Alamofire
This an expected behavior of PATCH endpoints and would make Alamofire easier to use for developers. Right now developers are forced to either have backend developers change to PUT endpoints, or when they are unable to change that, the iOS developers must spend many hours trying to implement a custom solution for PATCH endpoints.
Example of desired output when sending nil values through an Alamofire patch endpoint:
The text was updated successfully, but these errors were encountered: