Particle REST APİ

i have an REST api (on Django app. that not important). and i have an domain on heroku. i think i should be able to send an data (ex: variable) from photon to my rest api (as json). the algorithm is good. send from particle and should my rest app receive it. but dose not work :smiley:
First my particle code:

    /* RestClient simple GET request
     * credit: Chris Continanza (csquared)

    #include "rest_client.h"

    RestClient client = RestClient("");

    //RestClient client = RestClient("", 8000);

    String response;
    int statusCode;

    void setup() {

      while(!Serial.available()) Spark.process();

    void loop() {
        response = "";
        statusCode ="/sensors", "id=9&user_And_Owner_Sensors=5", &response);
        Serial.println("Status code from server: " + String(statusCode));
        Serial.println("Response body from server: " + response);

my Django Rest code is probly ture:

@api_view(['GET', 'POST'])
def snippet_list(request):
    List all snippets, or create a new snippet.
    if request.method == 'GET':
        snippets = SensorInfo.objects.all()
        serializer = Api(snippets, many=True)
        return Response(

    elif request.method == 'POST':
        serializer = Api(
        if serializer.is_valid():
            return Response(, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 

what i need is this code be working :
statusCode ="/sensors", "id=9&user_And_Owner_Sensors=5", &response);
look at second parameter i want to send tow value… “id” and user_And_Owner_Sensors. from photon to my REST (should be redy to GET that values).

if you will use domain not ip :
request.hostname =“your_server” Witout http://

The hostname is wrong.
http:// is not part of the host name but is the protocol prefix.
I also think that /sensors/ actually is not part of the hostname, but should rather go into the path

OP code has been updated since


not actually. i had tried witout http:// ore witout /sensors . but nothing.
note: i edit my code to :
http.get(request, response, headers);

in case
am able to see my data from putty. but dont know why cant any thing to my domain.

As long you are not showing the exact code you are running I doubt others would be willing to chase for something that might well be a red herring after pointing out the obvious errors in your code.

You are also not disclosing what extra info request.response provides you with. If you want us to help, you need to be more forthcoming with your “debug” info.

BTW, are you sure you want a GET request and not a POST or PUT?

OP code has been updated since

1 Like

Firstly am sorry. my english is bad. so i edit my post agin. i wish it understandable.
Yes like you said i need Posting data from photon to my REST. my REST code is good. and ready to recevie / GET values. Not put. just POST .

One additional point is that secure HTTPS (which you didn’t have in your original post) is not natively supported, you’d need to incorporate one of the 3rd party libraries to add that to your project.

1 Like

am sorry… how you know is my https dose not supported.
and is that mean all codes has no error ?
well Would you recommend some 3rd party lib to me.

I know that the Particle Photon does not support HTTPS because that support is not impemented in the Particle firmware.
But no, this does not mean that your code is free of errors, but since this (and the ones mentioned earlier) is the biggest obstacle for your code there was little point to look any further.

There are two possible libraries to add SSL/TLS support for HTTPS
Wolfssl [version 0.0.2; documenting]
TlsTcpClient library on WebIDE published


Hi. i do a little research about SSL. actually i dont need https at the moment. i just need send data from photon to my domain. i tried “rest_client.h” libary. as showed in my firs question. but no data sendind. then i tried “HttpClient.h” libary as show down. but nothing…
#include “application.h”

// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>

unsigned int nextTime = 0;    // Next time to contact the server
HttpClient http;

// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
      { "Content-Type", "application/json" },
        { NULL, NULL } // NOTE: Always terminate headers will NULL


http_request_t request;
http_response_t response;

void setup() {

void loop() {
    if (nextTime > millis()) {

    //Serial.println("Application>\tStart of Loop.");
    // Request path and body can be set at runtime or at setup.
    request.hostname = "";//my page which there a rest app. an ready to get data
    request.port = 80;

    //NOTE: Cant do Get or post. 
    // Get request, response, headers);
    nextTime = millis() + 1000;

I think there is little more than I can do since you keep ignoring my advice - look at your host name again!

1 Like

no am not ignoring your advice… i tried witout " http:// ". but no thing. So should i remove the part is coming afte “.com etc” .
look at this link please:

link is work. and if you look at it. you will see id and name as json data. if i post and data as {id=10, name=anas} should i remove “/data/2017/08/01/09.02.061268099243”.

If you tried without http:// why not post that version as you already have been told with it it’s plain out wrong?
You don’t even need to try that again - it’s just not going to work, full stop.

And also, why do you think?

after having read this

i said that before :sweat_smile:

[quote=“anasMansour, post:3, topic:34953”]
not actually. i had tried witout http:// ore witout /sensors . but nothing. [/quote]

i cant full stop. as i know ther are just tow lib to “POST” data from photon.
1- rest_client.h
2- httpClient.h
So i must POST from photon as soon as possible. i think rest_client just not support json data. so I guess i will use httpClient.

You said but your code never showed - not even the latest version after being told how to go about it correctly.

1 Like

edited my post. with [sloved].
thank you. when remove http:// and add right path to my rest api Worked.