Skip to content

HTTPRename #3

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

Open
wants to merge 3 commits 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
24 changes: 12 additions & 12 deletions RestClient.cpp → HTTPClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Client.h"
#include "RestClient.h"
#include "HTTPClient.h"

//#define HTTP_DEBUG true
#ifdef HTTP_DEBUG
Expand All @@ -11,7 +11,7 @@
#endif


RestClient::RestClient(Client& netClient, const char* _host) {
HTTPClient::HTTPClient(Client& netClient, const char* _host) {
host = _host;
port = 80;
num_headers = 0;
Expand All @@ -21,7 +21,7 @@ RestClient::RestClient(Client& netClient, const char* _host) {
this->timeout = 1000; // default. TODO: add a setter function
}

RestClient::RestClient(Client& netClient, const char* _host, int _port) {
HTTPClient::HTTPClient(Client& netClient, const char* _host, int _port) {
host = _host;
port = _port;
num_headers = 0;
Expand All @@ -30,42 +30,42 @@ RestClient::RestClient(Client& netClient, const char* _host, int _port) {
}

// GET path
int RestClient::get(String path){
int HTTPClient::get(String path){
return request("GET", path, "");
}

// POST path and body
int RestClient::post(String path, String body){
int HTTPClient::post(String path, String body){
return request("POST", path, body);
}

// PUT path and body
int RestClient::put(String path, String body){
int HTTPClient::put(String path, String body){
return request("PUT", path, body);
}

// DELETE path
int RestClient::del(String path){
int HTTPClient::del(String path){
return request("DELETE", path, "");
}

// DELETE path and body
int RestClient::del(String path, String body ){
int HTTPClient::del(String path, String body ){
return request("DELETE", path, body);
}

void RestClient::setHeader(String header){
void HTTPClient::setHeader(String header){
headers[num_headers] = header;
num_headers++;
}

void RestClient::setContentType(String contentTypeValue){
void HTTPClient::setContentType(String contentTypeValue){
contentType = contentTypeValue;
}

// The mother- generic request method.
//
int RestClient::request(const char* method, String path, String body){
int HTTPClient::request(const char* method, String path, String body){

HTTP_DEBUG_PRINT("HTTP: connect\n");

Expand Down Expand Up @@ -124,7 +124,7 @@ int RestClient::request(const char* method, String path, String body){
}
}

int RestClient::getResponse() {
int HTTPClient::getResponse() {
this->requestStart = millis();
// an http request ends with a blank line
boolean currentLineIsBlank = true;
Expand Down
6 changes: 3 additions & 3 deletions RestClient.h → HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include "Client.h"


class RestClient {
class HTTPClient {

public:
RestClient(Client& netClient, const char* _host);
RestClient(Client& netClient, const char* _host, int _port);
HTTPClient(Client& netClient, const char* _host);
HTTPClient(Client& netClient, const char* _host, int _port);

//Generic HTTP Request
int request(const char* method, String path, String body);
Expand Down
8 changes: 4 additions & 4 deletions examples/DweetGet/DweetGet.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Dweet.io GET client for RestClient library
Dweet.io GET client for HTTPClient library
Connects to dweet.io once every ten seconds,
sends a GET request and a request body. Uses SSL

Expand All @@ -16,12 +16,12 @@
char pass[] = "password"; // your network password

created 15 Feb 2016
updated 16 Feb 2016
updated 22 Feb 2016
by Tom Igoe

this example is in the public domain
*/
#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

Expand All @@ -30,7 +30,7 @@ int port = 80;
String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
Expand Down
12 changes: 6 additions & 6 deletions examples/DweetPost/DweetPost.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Dweet.io POST client for RestClient library
Dweet.io POST client for HTTPClient library
Connects to dweet.io once every ten seconds,
sends a POST request and a request body. Uses SSL

Expand All @@ -16,15 +16,15 @@

this example is in the public domain
*/
#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

char serverAddress[] = "dweet.io"; // server address
int port = 80;
int port = 443;

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
WiFiSSLClient wifi;
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
Expand Down Expand Up @@ -57,7 +57,7 @@ void loop() {

// assemble the body of the POST message:
int sensorValue = analogRead(A0);
String postData = "{\"sensorValue\":\"";
String postData = "{\"sensorValue\":\"";
postData += sensorValue;
postData += "\"}";

Expand Down
20 changes: 9 additions & 11 deletions examples/HueBlink/HueBlink.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* HueBlink example for RestClient library
/* HueBlink example for HTTPClient library

Uses ResClient library to control Philips Hue
Uses HTTPClient library to control Philips Hue
For more on Hue developer API see http://developer.meethue.com

To control a light, the Hue expects a HTTP PUT request to:
Expand All @@ -14,27 +14,27 @@
PUT request and the body of the request.

note: WiFi SSID and password are stored in config.h file.
If it is not present, add a new tab, call it "config.h"
If it is not present, add a new tab, call it "config.h"
and add the following variables:
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "password"; // your network password

modified 15 Feb 2016
modified 22 Feb 2016
by Tom Igoe (tigoe) to match new API
*/

#include <SPI.h>
#include <WiFi101.h>
#include <RestClient.h>
#include <HTTPClient.h>
#include "config.h"

int status = WL_IDLE_STATUS; // the Wifi radio's status
char hueHubIP[] = "192.168.0.3"; // IP address of the HUE bridge
String hueUserName = "huebridgeusername"; // hue bridge username

// make a wifi instance and a RestClient instance:
// make a wifi instance and a HTTPClient instance:
WiFiClient wifi;
RestClient restClient = RestClient(wifi, hueHubIP);
HTTPClient client = HTTPClient(wifi, hueHubIP);


void setup() {
Expand Down Expand Up @@ -81,13 +81,11 @@ void sendRequest(int light, String cmd, String value) {
Serial.print("JSON command to server: ");

// make the PUT request to the hub:
int statusCode = restClient.put(request, hueCmd);
int statusCode = client.put(request, hueCmd);
Serial.println(hueCmd);
Serial.print("Status code from server: ");
Serial.println(statusCode);
Serial.print("Server response: ");
Serial.println(restClient.readResponse());
Serial.println(client.readResponse());
Serial.println();
}


11 changes: 6 additions & 5 deletions examples/SimpleDelete/SimpleDelete.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
Simple DELETE client for RestClient library
Simple DELETE client for HTTPClient library
Connects to server once every five seconds, sends a DELETE request
and a request body

note: WiFi SSID and password are stored in config.h file.
If it is not present, add a new tab, call it "config.h"
If it is not present, add a new tab, call it "config.h"
and add the following variables:
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "password"; // your network password

created 14 Feb 2016
updated 22 Feb 2016
by Tom Igoe

this example is in the public domain
*/
#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

char serverAddress[] = "192.168.0.3"; // server address
int port = 8080;

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
Expand Down
11 changes: 6 additions & 5 deletions examples/SimpleGet/SimpleGet.ino
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
/*
Simple GET client for RestClient library
Simple GET client for HTTPClient library
Connects to server once every five seconds, sends a GET request

note: WiFi SSID and password are stored in config.h file.
If it is not present, add a new tab, call it "config.h"
If it is not present, add a new tab, call it "config.h"
and add the following variables:
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "password"; // your network password

created 14 Feb 2016
updated 22 Feb 2016
by Tom Igoe

this example is in the public domain
*/
#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

char serverAddress[] = "192.168.0.3"; // server address
int port = 8080;

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
Expand Down
11 changes: 6 additions & 5 deletions examples/SimplePost/SimplePost.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
Simple POST client for RestClient library
Simple POST client for HTTPClient library
Connects to server once every five seconds, sends a POST request
and a request body

note: WiFi SSID and password are stored in config.h file.
If it is not present, add a new tab, call it "config.h"
If it is not present, add a new tab, call it "config.h"
and add the following variables:
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "password"; // your network password

created 14 Feb 2016
updated 22 Feb 2016
by Tom Igoe

this example is in the public domain
*/
#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

char serverAddress[] = "192.168.0.3"; // server address
int port = 8080;

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
Expand Down
11 changes: 6 additions & 5 deletions examples/SimplePut/SimplePut.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
Simple PUT client for RestClient library
Simple PUT client for HTTPClient library
Connects to server once every five seconds, sends a PUT request
and a request body

note: WiFi SSID and password are stored in config.h file.
If it is not present, add a new tab, call it "config.h"
If it is not present, add a new tab, call it "config.h"
and add the following variables:
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "password"; // your network password

created 14 Feb 2016
updated 22 Feb 2016
by Tom Igoe

this example is in the public domain
*/
#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

char serverAddress[] = "192.168.0.3"; // server address
int port = 8080;

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
Expand Down
8 changes: 5 additions & 3 deletions examples/full_test_suite/full_test_suite.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* RestClient full test suite
/* HTTPClient full test suite

Every REST method is called.

by Chris Continanza (csquared)
modified by Massimo Banzi (mbanzi) to support more network devices
modified by Tom Igoe to match new API
updated 22 Feb 2016
by Tom Igoe
*/

#include <RestClient.h>
#include <HTTPClient.h>
#include <WiFi101.h>
#include "config.h"

Expand All @@ -18,7 +20,7 @@ char serverAddress[] = "192.168.0.3"; // server address
int port = 8080;

WiFiClient wifi;
RestClient client = RestClient(wifi, serverAddress, port);
HTTPClient client = HTTPClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;

void setup() {
Expand Down