RKParams Class Reference
Inherits from | NSInputStream |
Conforms to | RKRequestSerializable |
Declared in | RKParams.h RKParams.m |
Overview
This helper class implements the RKRequestSerializable protocol to provide support for creating the multi-part request body for RKRequest objects.
RKParams enables simple support for file uploading from NSData objects and files stored locally. RKParams will serialize these objects into a multi-part form representation that is suitable for submission to a remote web server for processing. After creating the RKParams object, use [RKClient post:params:delegate:] as the example below does.
Example:
RKParams *params = [RKParams params];
NSData *imageData = UIImagePNGRepresentation([_imageView image]);
[params setData:imageData MIMEType:@"image/png" forParam:@"image1"];
UIImage *image = [UIImage imageNamed:@"RestKit.png"];
imageData = UIImagePNGRepresentation(image);
[params setData:imageData MIMEType:@"image/png" forParam:@"image2"];
[_client post:@"/RKParamsExample" params:params delegate:self];
It is also used internally by RKRequest for its OAuth1 implementation.
Tasks
Creating an RKParams object
-
+ params
Creates and returns an RKParams object that is ready for population.
-
+ paramsWithDictionary:
Creates and returns an RKParams object created from a dictionary of key/value pairs.
-
– initWithDictionary:
Initalize an RKParams object from a dictionary of key/value pairs
Working with attachments
-
attachments
Array of all RKParamsAttachment attachments
property -
– setValue:forParam:
Creates a new RKParamsAttachment from the key/value pair passed in and adds it to the attachments array.
-
– setFile:forParam:
Creates a new RKParamsAttachment for a named parameter with the data contained in the file at the given path and adds it to the attachments array.
-
– setData:forParam:
Creates a new RKParamsAttachment for a named parameter with the data given and adds it to the attachments array.
-
– setData:MIMEType:forParam:
Creates a new RKParamsAttachment for a named parameter with the data given and the MIME type specified and adds it to the attachments array.
-
– setData:MIMEType:fileName:forParam:
Creates a new RKParamsAttachment and sets the value for a named parameter to a data object with the specified MIME Type and attachment file name.
-
– setFile:MIMEType:fileName:forParam:
Creates a new RKParamsAttachment and sets the value for a named parameter to the data contained in a file at the given path with the specified MIME Type and attachment file name.
-
– dictionaryOfPlainTextParams
Get the dictionary of params which are plain text as specified by RFC 5849.
Resetting and checking states
-
– reset
Resets the state of the RKParams stream.
-
– MD5
Return a composite MD5 checksum value for all attachments.
HTTP Headers
-
– HTTPHeaderValueForContentType
The value of the Content-Type header for the HTTP Body representation of the serialization.
-
– HTTPHeaderValueForContentLength
Returns the length of the HTTP Content-Length header.
-
– HTTPBodyStream
Returns an input stream for reading the serialization as a stream used to provide support for handling large HTTP payloads.
Properties
attachments
Array of all RKParamsAttachment attachments
@property (nonatomic, readonly) NSMutableArray *attachments
Declared In
RKParams.h
Class Methods
params
Creates and returns an RKParams object that is ready for population.
+ (RKParams *)params
Return Value
An RKParams object to be populated.
Declared In
RKParams.h
paramsWithDictionary:
Creates and returns an RKParams object created from a dictionary of key/value pairs.
+ (RKParams *)paramsWithDictionary:(NSDictionary *)dictionary
Parameters
- dictionary
NSDictionary of key/value pairs to add as RKParamsAttachment objects.
Return Value
An RKParams object with the key/value pairs of the dictionary.
Declared In
RKParams.h
Instance Methods
HTTPBodyStream
Returns an input stream for reading the serialization as a stream used to provide support for handling large HTTP payloads.
- (NSInputStream *)HTTPBodyStream
Return Value
An input stream for reading the serialization as a stream.
Declared In
RKRequestSerializable.h
HTTPHeaderValueForContentLength
Returns the length of the HTTP Content-Length header.
- (NSUInteger)HTTPHeaderValueForContentLength
Return Value
Unsigned integer length of the HTTP Content-Length header.
Declared In
RKRequestSerializable.h
HTTPHeaderValueForContentType
The value of the Content-Type header for the HTTP Body representation of the serialization.
- (NSString *)HTTPHeaderValueForContentType
Return Value
A string value of the Content-Type header for the HTTP body.
Declared In
RKRequestSerializable.h
MD5
Return a composite MD5 checksum value for all attachments.
- (NSString *)MD5
Declared In
RKParams.h
dictionaryOfPlainTextParams
- (NSDictionary *)dictionaryOfPlainTextParams
Return Value
NSDictionary of key/values extracting from the RKParamsAttachment objects that meet the plain text criteria
Discussion
This is largely used for RKClient’s OAuth1 implementation.
The params in this dictionary include those where:
- The entity-body is single-part.
- The entity-body follows the encoding requirements of the “application/x-www-form-urlencoded” content-type as defined by [W3C.REC-html40-19980424].
- The HTTP request entity-header includes the “Content-Type” header field set to “application/x-www-form-urlencoded”.
Declared In
RKParams.h
initWithDictionary:
Initalize an RKParams object from a dictionary of key/value pairs
- (RKParams *)initWithDictionary:(NSDictionary *)dictionary
Parameters
- dictionary
NSDictionary of key/value pairs to add as RKParamsAttachment objects.
Return Value
An RKParams object with the key/value pairs of the dictionary.
Declared In
RKParams.h
setData:MIMEType:fileName:forParam:
Creates a new RKParamsAttachment and sets the value for a named parameter to a data object with the specified MIME Type and attachment file name.
- (RKParamsAttachment *)setData:(NSData *)data MIMEType:(NSString *)MIMEType fileName:(NSString *)fileName forParam:(NSString *)param
Parameters
- data
NSData object of the data to be attached
- MIMEType
String of the MIME type of the data
- fileName
String of the attachment file name
- param
Key name of the attachment to add
Return Value
the new RKParamsAttachment that was added to the attachments array
Discussion
Bug: DEPRECATED: Use [RKParams setData:MIMEType:forParam:] and set the fileName on the returned RKParamsAttachment instead.
Declared In
RKParams.h
setData:MIMEType:forParam:
Creates a new RKParamsAttachment for a named parameter with the data given and the MIME type specified and adds it to the attachments array.
- (RKParamsAttachment *)setData:(NSData *)data MIMEType:(NSString *)MIMEType forParam:(NSString *)param
Parameters
- data
NSData object of the data to be attached
- MIMEType
String of the MIME type of the data
- param
Key name of the attachment to add
Return Value
the new RKParamsAttachment that was added to the attachments array
Declared In
RKParams.h
setData:forParam:
Creates a new RKParamsAttachment for a named parameter with the data given and adds it to the attachments array.
- (RKParamsAttachment *)setData:(NSData *)data forParam:(NSString *)param
Parameters
- data
NSData object of the data to be attached
- param
Key name of the attachment to add
Return Value
the new RKParamsAttachment that was added to the attachments array
Discussion
A default MIME type of application/octet-stream will be used.
Declared In
RKParams.h
setFile:MIMEType:fileName:forParam:
Creates a new RKParamsAttachment and sets the value for a named parameter to the data contained in a file at the given path with the specified MIME Type and attachment file name.
- (RKParamsAttachment *)setFile:(NSString *)filePath MIMEType:(NSString *)MIMEType fileName:(NSString *)fileName forParam:(NSString *)param
Parameters
- filePath
String of the path to the file to be attached
- MIMEType
String of the MIME type of the data
- fileName
String of the attachment file name
- param
Key name of the attachment to add
Return Value
the new RKParamsAttachment that was added to the attachments array
Discussion
Bug: DEPRECATED: Use [RKParams setFile:forParam:] and set the MIMEType and fileName on the returned RKParamsAttachment instead.
Declared In
RKParams.h
setFile:forParam:
Creates a new RKParamsAttachment for a named parameter with the data contained in the file at the given path and adds it to the attachments array.
- (RKParamsAttachment *)setFile:(NSString *)filePath forParam:(NSString *)param
Parameters
- filePath
String of the path to the file to be attached
- param
Key name of the attachment to add
Return Value
the new RKParamsAttachment that was added to the attachments array
Declared In
RKParams.h
setValue:forParam:
Creates a new RKParamsAttachment from the key/value pair passed in and adds it to the attachments array.
- (RKParamsAttachment *)setValue:(id<NSObject>)value forParam:(NSString *)param
Parameters
- value
Value of the attachment to add
- param
Key name of the attachment to add
Return Value
the new RKParamsAttachment that was added to the attachments array
Declared In
RKParams.h