Skip to content
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

Two new methods to access response headers #12

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5e21983
Using legacy ssl api before I start work on migrating
Duckle29 Mar 7, 2019
af92d7e
Create library.json
Duckle29 Mar 10, 2019
22cd144
Changed name
Duckle29 Mar 10, 2019
b28260a
started work on moving to bearssl API
Duckle29 Mar 10, 2019
0627605
Started work on moving to bearssl
Duckle29 Mar 10, 2019
5167b95
changed name
Duckle29 Mar 10, 2019
52a30f5
changed name
Duckle29 Mar 10, 2019
bb8f270
Fixed git url
Duckle29 Mar 10, 2019
515a742
Fixed git url
Duckle29 Mar 10, 2019
1640813
Removed line
Duckle29 Mar 10, 2019
8bb149a
Merge branch 'master' into 2.0
Duckle29 Mar 10, 2019
ee61e94
Merge pull request #1 from Hal9k-dk/2.0
Duckle29 Mar 10, 2019
d789a86
Used library.properties instead, to be arduino compatible
Duckle29 Mar 10, 2019
9a7ad37
Updated readme
Duckle29 Mar 11, 2019
cda6e93
Update README.md
Duckle29 Mar 11, 2019
c7d03a7
Added test example for esp
Duckle29 Mar 11, 2019
5d41d3b
Added wifi connection to example
Duckle29 Mar 11, 2019
c41a1b1
Merge branch 'master' of github.com:Hal9k-dk/esp8266-restclient
Duckle29 Mar 11, 2019
31eb785
Actually include wifi library
Duckle29 Mar 11, 2019
1cc9d3b
Actually include wifi library
Duckle29 Mar 11, 2019
704de90
changed baud-rate
Duckle29 Mar 11, 2019
11a1cee
fixed path
Duckle29 Mar 11, 2019
80772df
Added port setter function
Duckle29 Mar 11, 2019
cda4fff
Increased test delay
Duckle29 Mar 11, 2019
bbfe5db
Increased test delay
Duckle29 Mar 11, 2019
d7da72e
Sprinkled some delay(0) to avoid WDT resets
Duckle29 Mar 11, 2019
3c81715
Sprinkled some delay(0) to avoid WDT resets
Duckle29 Mar 11, 2019
ee38245
Set myself as maintainer
Duckle29 Mar 12, 2019
8763151
Updated readme
Duckle29 Mar 12, 2019
ad7a014
Changed name
Duckle29 Mar 12, 2019
16284d1
Merge branch 'master' of github.com:Hal9k-dk/esp8266-restclient
Duckle29 Mar 12, 2019
ce9f8e4
Changed baudrate as arduino had issues with it
Duckle29 Mar 12, 2019
1a2486c
Initialize member variables.
bullestock Sep 7, 2019
1e2604d
Change SSL argument to bool.
bullestock Sep 7, 2019
ebd3b5a
Fix bug where last part of response could be lost.
bullestock Sep 7, 2019
f8195f1
Ensure that we run the state machine for bytes received after the con…
bullestock Sep 12, 2019
abdae4a
Update library.properties
Duckle29 Oct 16, 2019
898a677
New methods to access raw response and specific response header,
dudzio12 Dec 14, 2019
e346ff6
Fixed position and added debugging lines.
dudzio12 Dec 14, 2019
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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
116 changes: 78 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

HTTP Request library for Arduino and the ESP8266 WiFi SOC modules

This library now supports SSL! To use with SSL, you need to include the SHA1 fingerprint of the certificate of the site you are connecting to. You can get this by using a desktop browser and inspecting the SSL cert used at the site. Please note: this is FRAGILE, if the site updates their SSL, your code will break. But, there is not enough memory on the ESP8266 to store all the rool certs, so this is a working method. Se the example below.
This library supports SSL!
To use with SSL either include the SHA1 fingerprint of the certificate of the site you are connecting to, or force the library to use ssl insecurely (don't veryify the server is who it says it is).

You can get the SHA1 fingerprint by using a desktop browser and inspecting the SSL cert used at the site. Please note: this is FRAGILE, if the site updates their SSL, your code will break. But, there is not enough memory on the ESP8266 to store all the rool certs, so this is a working method. Se the example below.

This library is derived almost entirely from the great work done here: https://github.com/csquared/arduino-restclient

# Fork note

API I used returns token inside response header, there was no way to access it, so I've managed to prepare two more functions. One for full access to raw response, and the second to fetch specific header value in simplest possible way.
I have no time to prepare full test suites, but it should work on any environments.

# Install

Clone (or download and unzip) the repository to `~/Documents/Arduino/libraries`
Expand All @@ -16,92 +24,124 @@ where `~/Documents/Arduino` is your sketchbook directory.
> cd libraries
> git clone https://github.com/dakaz/esp8266-restclient.git RestClient

# Usage

### Include
# Dependencies

You need to have the `ESP8266` board support already included.
You need to have the `ESP8266` board support already installed.

### RestClient(host/ip, [port])
# Usage

Constructor to create an RestClient object to make requests against.
```c++
RestClient(const char* host/ip, [int port], [bool force / const char* fingerprint]);
```

Use domain name and default to port 80:
Use a domain name and default to port 80:
```c++
RestClient client = RestClient("arduino-http-lib-test.herokuapp.com");
RestClient client = RestClient("esp-rest-test.herokuapp.com");
```

Use a local IP and an explicit port:
```c++
RestClient client = RestClient("192.168.1.50",5000);
RestClient client = RestClient("192.168.1.50", 5000);
```

Use a local IP, an explicit port to an SSL site and (must include the 1 to turn on SSL):
Use a domain name, an explicit port to an SSL site and verify the certificate with its fingerprint:
```c++
RestClient client = RestClient("www.kudoso.com",443, 1);
RestClient client = RestClient("www.kudoso.com", 443, "EE 16 77 79 55 58 92 46 FB 18 40 99 2E 17 7E AB 32 0A 4A 88");
```

Use a local IP, an explicit port to an SSL site and verify the certificate with its fingerprint:
Use a domain name, an explicit port to an SSL site and force insecure SSL with no certificate verification:
```c++
RestClient client = RestClient("www.kudoso.com",443, "EE 16 77 79 55 58 92 46 FB 18 40 99 2E 17 7E AB 32 0A 4A 88");
RestClient client = RestClient("www.kudoso.com", 443, 1);
```

### dhcp()

Sets up `EthernetClient` with a mac address of `DEADBEEFFEED`. Returns `true` or `false` to indicate if setting up DHCP
was successful or not
was successful or not. Not used on the ESP.

## RESTful methods

All methods return an HTTP status code or 0 if there was an error.

### `get(const char* path)`
### `get(const char* path, String* response)`

Start making requests!

## GET

```c++
int statusCode = client.get("/"));
get(const char* path, [String* response]);
```

Pass in a string *by reference* for the response:
Examples:
```c++
int statusCode = client.get("/");
```

```c++
String response = "";
int statusCode = client.get("/", &response);
```

### post(const char* path, const char* body)
### post(const char* path, String* response)
### post(const char* path, const char* body, String* response)
## POST

There are three different overloads of post:
```c++
post(const char* path, const char* body);
post(const char* path, String* response);
post(const char* path, const char* body, String* response);
```

Examples:
```c++
String response = "";
int statusCode = client.post("/", &response);
statusCode = client.post("/", "foo=bar");
response = "";
statusCode = client.post("/", "foo=bar", &response);
```

### put(const char* path, const char* body)
### put(const char* path, String* response)
### put(const char* path, const char* body, String* response)
```c++
const char* post_body = "{foo: 'bar', bob: 'alice'}";

int statusCode = client.post("/", post_body);
```

```c++
String response = "";
int statusCode = client.put("/", &response);
statusCode = client.put("/", "foo=bar");
response = "";
statusCode = client.put("/", "foo=bar", &response);
const char* post_body = "{foo: 'bar', bob: 'alice'}";

int statusCode = client.post("/", post_body, &response);
```

### del(const char* path)
### del(const char* path, const char* body)
### del(const char* path, String* response)
### del(const char* path, const char* body, String* response)
## PUT

```c++
put(const char* path, const char* body);
put(const char* path, String* response);
put(const char* path, const char* body, String* response);
```
String response = "";
int statusCode = client.del("/", &response);

## DEL

```c++
del(const char* path);
del(const char* path, const char* body);
del(const char* path, String* response);
del(const char* path, const char* body, String* response);
```

## Additional function implemented in this fork

```c++
// Get raw response (without body)
getRawLastResponse();
// Get response header value by key
getResponseHeader(const char* key, String*);
```

Examples:

```c++
String rawResponse = client.getRawLastResponse();
String headerValue;
client.getResponseHeader("Token", &headerValue);
```

## Full Example
Expand Down
Loading