GithubHelp home page GithubHelp logo

arthurguy / spark-restclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from llad/spark-restclient

0.0 2.0 0.0 123 KB

RESTful HTTP Request Library for the Spark Core

License: MIT License

Arduino 44.65% C++ 55.35%

spark-restclient's Introduction

RestClient for the Spark Core

HTTP Request library for the Spark Core. A lightly adjusted version of the RestClient for Arduino from Chris Continanza available here: https://github.com/csquared/arduino-restclient

Install

Add the files rest_client.cpp and rest_client.h to your app somehow... I just cut and paste into the Spark.io Web IDE.

Usage

RestClient(host/ip, [port])

Constructor to create an RestClient object to make requests against.

Use domain name and default to port 80:

RestClient client = RestClient("www.some-http-server.com");

Use a local IP and an explicit port:

RestClient client = RestClient("192.168.1.50",5000);

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!

int statusCode = client.get("/"));

Pass in a string by reference for the response:

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)

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)

String response = "";
int statusCode = client.put("/", &response);
statusCode = client.put("/", "foo=bar");
response = "";
statusCode = client.put("/", "foo=bar", &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)

String response = "";
int statusCode = client.del("/", &response);

Full Example

I test every way of calling the library (against a public heroku app)[https://github.com/csquared/arduino-http-test].

You can find the file in File->Examples->RestClient->full_test_suite

Debug Mode

If you're having trouble, you can always open RestClient.cpp and throw at the top:

#define HTTP_DEBUG

Everything happening in the client will get printed to the Serial port.

Thanks/Credit

So far, I have just made a few minor adjustments to the excellent work of Chris Continanza, available here: https://github.com/csquared/arduino-restclient. Thanks, Chris!

spark-restclient's People

Contributors

csquared avatar arthurguy avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.