Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

added support for payload in DELETE requests #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Classes/LRRestyClient+DELETE.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
*/
- (LRRestyRequest *)delete:(NSString *)urlString headers:(NSDictionary *)headers withBlock:(LRRestyResponseBlock)block;

/**
Performs a DELETE request on URL resource with block response handling.
@param urlString The URL resource to delete.
@param payload The HTTP request body
@param headers A dictionary of HTTP request headers.
@param block The response handler.
@returns The request object.
*/
- (LRRestyRequest *)delete:(NSString *)urlString payload:(id)payload headers:(NSDictionary *)headers withBlock:(LRRestyResponseBlock)block;

#pragma mark -
#pragma mark Synchronous API

Expand Down
9 changes: 7 additions & 2 deletions Classes/LRRestyClient+DELETE.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (LRRestyRequest *)delete:(NSString *)urlString delegate:(id<LRRestyClientRespo

- (LRRestyRequest *)delete:(NSString *)urlString headers:(NSDictionary *)headers delegate:(id<LRRestyClientResponseDelegate>)delegate;
{
return [HTTPClient DELETE:[NSURL URLWithString:urlString] headers:headers delegate:[LRRestyClientProxyDelegate proxyForClient:self responseDelegate:delegate]];
return [HTTPClient DELETE:[NSURL URLWithString:urlString] payload:nil headers:headers delegate:[LRRestyClientProxyDelegate proxyForClient:self responseDelegate:delegate]];
}

#pragma mark -
Expand All @@ -37,7 +37,12 @@ - (LRRestyRequest *)delete:(NSString *)urlString withBlock:(LRRestyResponseBlock

- (LRRestyRequest *)delete:(NSString *)urlString headers:(NSDictionary *)headers withBlock:(LRRestyResponseBlock)block;
{
return [HTTPClient DELETE:[NSURL URLWithString:urlString] headers:headers delegate:[LRRestyClientBlockDelegate delegateWithBlock:block]];
return [HTTPClient DELETE:[NSURL URLWithString:urlString] payload:nil headers:headers delegate:[LRRestyClientBlockDelegate delegateWithBlock:block]];
}

- (LRRestyRequest *)delete:(NSString *)urlString payload:(id)payload headers:(NSDictionary *)headers withBlock:(LRRestyResponseBlock)block
{
return [HTTPClient DELETE:[NSURL URLWithString:urlString] payload:payload headers:headers delegate:[LRRestyClientBlockDelegate delegateWithBlock:block]];
}

#pragma mark -
Expand Down
2 changes: 1 addition & 1 deletion Classes/LRRestyHTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- (LRRestyRequest *)GET:(NSURL *)url parameters:(NSDictionary *)parameters headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
- (LRRestyRequest *)POST:(NSURL *)url payload:(id)payload headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
- (LRRestyRequest *)PUT:(NSURL *)url payload:(id)payload headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
- (LRRestyRequest *)DELETE:(NSURL *)url headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
- (LRRestyRequest *)DELETE:(NSURL *)url payload:(id)payload headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
- (LRRestyRequest *)performRequest:(LRRestyRequest *)request;
- (void)cancelAllRequests;
@end
Expand Down
4 changes: 2 additions & 2 deletions Classes/LRRestyHTTPClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ - (LRRestyRequest *)PUT:(NSURL *)url payload:(id)payload headers:(NSDictionary *
return [self performRequest:[self requestForURL:url method:@"PUT" payload:payload headers:headers requestDelegate:requestDelegate]];
}

- (LRRestyRequest *)DELETE:(NSURL *)url headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
- (LRRestyRequest *)DELETE:(NSURL *)url payload:(id)payload headers:(NSDictionary *)headers delegate:(id<LRRestyRequestDelegate>)requestDelegate;
{
return [self performRequest:[self requestForURL:url method:@"DELETE" payload:nil headers:headers requestDelegate:requestDelegate]];
return [self performRequest:[self requestForURL:url method:@"DELETE" payload:payload headers:headers requestDelegate:requestDelegate]];
}

- (LRRestyRequest *)performRequest:(LRRestyRequest *)request;
Expand Down
17 changes: 17 additions & 0 deletions Tests/Acceptance/DeleteResourceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ - (void)testCanPerformDeleteRequestWithCustomHeaders
assertEventuallyThat(&lastResponse, is(responseWithRequestEcho(@"env.HTTP_X_TEST_HEADER", @"Resty")));
}

- (void)testCanPerformDeleteRequestWithHTTPBody
{
__block LRRestyResponse *testLocalResponse = nil;
NSString *payload = @"{\"foo\":\"bar\"}";
mimicDELETE(@"/simple/resource", andEchoRequest(), ^{
[client delete:resourceWithPath(@"/simple/resource")
payload:payload
headers:[NSDictionary dictionaryWithObject:@"Resty" forKey:@"X-Test-Header"]
withBlock:^(LRRestyResponse *response) {
testLocalResponse = [response retain];
}];
});

assertEventuallyThat(&lastResponse, is(responseWithRequestEcho(@"body", payload)));
[testLocalResponse release];
}

- (void)testCanModifyRequestsBeforeTheyAreSentUsingBlock
{
mimicDELETE(@"/simple/resource", andEchoRequest(), ^{
Expand Down