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

MASRequestBuilder only accept dictionary as body #285

@sandersaelmans

Description

@sandersaelmans

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions