Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

MASRequestBuilder only accept dictionary as body #285

Open
sandersaelmans opened this issue Jun 30, 2021 · 0 comments
Open

MASRequestBuilder only accept dictionary as body #285

sandersaelmans opened this issue Jun 30, 2021 · 0 comments

Comments

@sandersaelmans
Copy link

sandersaelmans commented Jun 30, 2021

PR: #291

Currently the MASRequest builder only accepts an NSDictionary as the request body. This is an issue as not all (of our) endpoints expect a dictionary as the root object of a request's body.

Some possible fixes could be to:

  1. use id as the body's type (this change does not existing impact users when they update).
  2. use NSData as the body's type (breaking change and users have to encode the json themselves. Offers flexibility however).
  3. Introduce a JSONObject class as the body's type (JSONObject would then be initializable with all valid json data types: NSNumber, NSString, Bool, NSDictionary, NSArray, etc. This limits the amount of "valid" types a user could use to set the request body):
@interface MASJsonObject: NSObject

@property (nonatomic, strong) id value;

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithString:(NSString *)string;
- (instancetype)initWithBool:(BOOL)boolean;
- (instancetype)initWithNumber:(NSNumber *)number;
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (instancetype)initWithArray:(NSArray *)array;

@end


@implementation MASJsonObject

- (instancetype)initWithString:(NSString *)string {
   self = [super init];
   if (self)
   {
       self.value = string;
   }
   return self;
}

// etc...

@end
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant