RdWebServer (community library)
Summary
Name | Value |
---|---|
Name | RdWebServer |
Version | 1.0.17 |
Installs | |
License | MIT |
Author | Rob Dobson |
URL | https://github.com/robdobsn/ParticleRdWebServer |
Repository | https://github.com/robdobsn/ParticleRdWebServer.git |
Download | .tar.gz |
All Versions | 1.0.17, 1.0.14, 1.0.5 |
Simple web server supporting REST API and static files
Example Build Testing
Device OS Version:
This table is generated from an automated build. Success only indicates that the code compiled successfully.
Library Read Me
This content is provided by the library maintainer and has not been validated or approved.
RdWebServer
Library for a simple web server which supports a REST API and static pages/images
Usage
#include "RdWebServer.h"
#include "GenResources.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(AUTOMATIC);
// Web server
RdWebServer* pWebServer = NULL;
void setup()
{
// Construct server
pWebServer = new RdWebServer();
// Configure web server
if (pWebServer)
{
// Add resources to web server
pWebServer->addStaticResources(genResources, genResourcesCount);
// Start the web server
pWebServer->start(webServerPort);
}
}
void loop()
{
// Service the web server
if (pWebServer)
pWebServer->service();
}
See the examples folder for more details.
Documentation
To add a REST API:
- Include the RestAPIEndpoints helper
// API Endpoints
#include "RestAPIEndpoints.h"
RestAPIEndpoints restAPIEndpoints;
- Create a method to handle the callback that you will receive from RdWebServer when the API endpoint is hit
void restAPI_QueryStatus(RestAPIEndpointMsg& apiMsg, String& retStr)
{
retStr = "{\"rslt\":\"ok\"}";
}
- Register the endpoint with RestAPIEndpoint helper - do this anywhere in setup()
restAPIEndpoints.addEndpoint("Q", RestAPIEndpointDef::ENDPOINT_CALLBACK, restAPI_QueryStatus, "");
- Add the endpoint definitions to the server
Do this after the pWebServer has been initialized to point to the instance of an RdWebServer
// Add resources to web server
pWebServer->addStaticResources(genResources, genResourcesCount);
LICENSE
Copyright 2017 Rob Dobson
Licensed under the MIT license
Browse Library Files