Skip to content

Commit

Permalink
v2 - refactor (#3)
Browse files Browse the repository at this point in the history
* add methods for upload handler

* fix signatures

* use actually exported type for web request type

* remove path handlers (will be in rich_http_server)

* remove handler code -- library now just has the URL token processing

* add example

* README formatting

* bump version

* remove extraneous line
  • Loading branch information
sidoh authored May 2, 2019
1 parent 3631a3c commit d7fe45d
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 509 deletions.
20 changes: 1 addition & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,14 @@ cache:
install:
- pip install -U platformio
- platformio update
- platformio lib -g install 'ESP Async WebServer'

matrix:
include:
- env:
- PLATFORMIO_CI_SRC=examples/esp8266_simple
- PLATFORMIO_CI_SRC=examples/simple
- PLATFORMIO_ADDITIONAL_ARGS='--lib=.'
- BOARDS=--board=d1_mini
- PLATFORMIO_CMD=ci
- env:
- PLATFORMIO_CI_SRC=examples/esp8266_async_webserver
- PLATFORMIO_ADDITIONAL_ARGS='--lib=.'
- PLATFORMIO_BUILD_FLAGS=-DPVH_USE_ASYNC_WEBSERVER
- BOARDS=--board=d1_mini
- PLATFORMIO_CMD=ci
- env:
- PLATFORMIO_CI_SRC=examples/esp32_simple
- PLATFORMIO_ADDITIONAL_ARGS='--lib=.'
- BOARDS=--board=esp32doit-devkit-v1
- PLATFORMIO_CMD=ci
- env:
- PLATFORMIO_CI_SRC=examples/esp32_async_webserver
- PLATFORMIO_ADDITIONAL_ARGS='--lib=.'
- PLATFORMIO_BUILD_FLAGS=-DPVH_USE_ASYNC_WEBSERVER
- BOARDS=--board=esp32doit-devkit-v1
- PLATFORMIO_CMD=ci
- env:
- PLATFORMIO_CMD=test

Expand Down
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# Path Variable Handlers [![Build Status](https://travis-ci.org/sidoh/path_variable_handlers.svg?branch=master)](https://travis-ci.org/sidoh/path_variable_handlers)

This is a library for handling HTTP and REST paths containing variables. Many RESTful APIs contain resources that have variables in their paths (e.g., `/things/:thing_id`). This library exposes a way to easily process such resource paths in a low-effort way.
This is a library for handling paths. Many RESTful APIs contain resources that have variables in their paths (e.g., `/things/:thing_id`). This library exposes a way to process such resource paths in a low-effort way.

Compatible with ESP8266 and ESP32 builtin web servers, and ESPAsyncWebServer for both platforms.
While this is mostly useful for REST APIs, it could also be used, for example, to process MQTT topics containing wildcards.

### Examples
There is nothing platform-specific about this library.

Examples are found in the `./examples` directory. This is the easiest way to get started.

## Compatible Hardware
## Examples

This library is built on top of handler bindings tied to the espressif platform:

* ESP32
* Builtin `WebServer`.
* [`ESPAsyncWebServer`](https://github.com/me-no-dev/ESPAsyncWebServer).
* ESP266: uses the `ESP8266WebServer` bindings built into the SDK by default.
* Builtin `ESP8266WebServer`.
* ESPAsyncWebServer.
Examples are found in the `./examples` directory. This is the easiest way to get started.

Defaults to the builtin web server bindings. To use `ESPAsyncWebServer`, set the build flag `PVH_USE_ASYNC_WEBSERVER`.
## Development

Run tests with:
Expand All @@ -31,7 +21,7 @@ platformio test
Build examples with, for instance:

```
platformio ci --board=d1_mini --lib=. examples/esp8266_simple
platformio ci --board=d1_mini --lib=. examples/simple
```

#### New Release
Expand Down
52 changes: 0 additions & 52 deletions examples/esp32_async_webserver/ESP32AsyncWebServer.ino

This file was deleted.

54 changes: 0 additions & 54 deletions examples/esp32_simple/ESP32Simple.ino

This file was deleted.

52 changes: 0 additions & 52 deletions examples/esp8266_async_webserver/ESP8266AsyncWebServer.ino

This file was deleted.

54 changes: 0 additions & 54 deletions examples/esp8266_simple/ESP8266SimplePathVariable.ino

This file was deleted.

25 changes: 25 additions & 0 deletions examples/simple/Simple.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <Arduino.h>

#include <TokenIterator.h>
#include <UrlTokenBindings.h>

void setup() {
Serial.begin(115200);

char p1[] = "example/path/a/b/c";
char p2[] = "example/path/:var1/:var2/:var3";

TokenIterator itr1(p1, strlen(p1), '/');
TokenIterator itr2(p2, strlen(p2), '/');
UrlTokenBindings bindings(itr1, itr2);

if (bindings.hasBinding("var1")) { // has this one
Serial.println(bindings.get("var1")); // will print "a"
}

if (bindings.hasBinding("var4")) {
// does not have this binding
}
}

void loop() { }
7 changes: 2 additions & 5 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
],
"license": "MIT",
"dependencies": { },
"version": "1.1.0",
"version": "2.0.0",
"frameworks": "arduino",
"platforms": [
"espressif8266",
"espressif32"
],
"platforms": "*",
"examples": "examples/*/*.ino",
"exclude": [
"platformio.ini",
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=PathVariableHandlers
version=1.1.0
version=2.0.0
author=Chris Mullins <[email protected]>
maintainer=Chris Mullins <[email protected]>
sentence=Library for handling paths containing variables.
paragraph=Many RESTful APIs contain resources that have variables in their paths (e.g., /things/:thing_id). This library exposes a way to easily process such resource paths in a low-effort way. Compatible with ESP8266WebServer for ESP8266 and ESPAsyncWebServer for ESP32.
category=Communication
url=https://github.com/sidoh/path_variable_handlers
architectures=esp8266,esp32
architectures=*
Loading

0 comments on commit d7fe45d

Please sign in to comment.