Skip to content

Add support for PATCH operations #18

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

Merged
merged 1 commit into from
Jan 12, 2017
Merged
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
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WebSocketClient KEYWORD1
get KEYWORD2
post KEYWORD2
put KEYWORD2
patch KEYWORD2
startRequest KEYWORD2
beginRequest KEYWORD2
sendHeader KEYWORD2
Expand Down
25 changes: 25 additions & 0 deletions src/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,31 @@ int HttpClient::put(const char* aURLPath, const char* aContentType, int aContent
return startRequest(aURLPath, HTTP_METHOD_PUT, aContentType, aContentLength, aBody);
}

int HttpClient::patch(const char* aURLPath)
{
return startRequest(aURLPath, HTTP_METHOD_PATCH);
}

int HttpClient::patch(const String& aURLPath)
{
return patch(aURLPath.c_str());
}

int HttpClient::patch(const char* aURLPath, const char* aContentType, const char* aBody)
{
return patch(aURLPath, aContentType, strlen(aBody), (const byte*)aBody);
}

int HttpClient::patch(const String& aURLPath, const String& aContentType, const String& aBody)
{
return patch(aURLPath.c_str(), aContentType.c_str(), aBody.length(), (const byte*)aBody.c_str());
}

int HttpClient::patch(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[])
{
return startRequest(aURLPath, HTTP_METHOD_PATCH, aContentType, aContentLength, aBody);
}

int HttpClient::del(const char* aURLPath)
{
return startRequest(aURLPath, HTTP_METHOD_DELETE);
Expand Down
19 changes: 19 additions & 0 deletions src/HttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const int HTTP_ERROR_INVALID_RESPONSE =-4;
#define HTTP_METHOD_GET "GET"
#define HTTP_METHOD_POST "POST"
#define HTTP_METHOD_PUT "PUT"
#define HTTP_METHOD_PATCH "PATCH"
#define HTTP_METHOD_DELETE "DELETE"
#define HTTP_HEADER_CONTENT_LENGTH "Content-Length"
#define HTTP_HEADER_CONTENT_TYPE "Content-Type"
Expand Down Expand Up @@ -104,6 +105,24 @@ class HttpClient : public Client
int put(const String& aURLPath, const String& aContentType, const String& aBody);
int put(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]);

/** Connect to the server and start to send a PATCH request.
@param aURLPath Url to request
@return 0 if successful, else error
*/
int patch(const char* aURLPath);
int patch(const String& aURLPath);

/** Connect to the server and send a PATCH request
with body and content type
@param aURLPath Url to request
@param aContentType Content type of request body
@param aBody Body of the request
@return 0 if successful, else error
*/
int patch(const char* aURLPath, const char* aContentType, const char* aBody);
int patch(const String& aURLPath, const String& aContentType, const String& aBody);
int patch(const char* aURLPath, const char* aContentType, int aContentLength, const byte aBody[]);

/** Connect to the server and start to send a DELETE request.
@param aURLPath Url to request
@return 0 if successful, else error
Expand Down