---
# System prepended metadata

title: Server REST
tags: [WebService]

---

###### tags: `WebService`

# Server REST
exemple ligne web:
http://localhost:1880/lamp?state=on


Pour pouvoir voir toutes les infos:



## exemple Node-red server ADD/SUB/MUL/DIV
![](https://i.imgur.com/yNO6EEx.png)
![](https://i.imgur.com/Ql3BHMt.png)


trouver les chemin des variables:
![](https://i.imgur.com/RBnsnpe.png)

ensuite aller regarder les chemins des variables
![](https://i.imgur.com/8Vx4x6Y.png)

code dans la function:
```
 var step, result;
 
if(msg.req._parsedUrl.pathname=="/add"){
    step=1;
}

else if(msg.req._parsedUrl.pathname=="/sub"){
    step=2;
}
else if(msg.req._parsedUrl.pathname=="/mul"){
    step=3;
}
else if(msg.req._parsedUrl.pathname=="/div"){
    step=4;
}



switch(step) {
  case 1:
   result=1*msg.payload.x+msg.payload.y*1;
    break;
  case 2:
    result=1*msg.payload.x-msg.payload.y;
    break;
     case 3:
    result=1*msg.payload.x*msg.payload.y;
    break;
     case 4:
    result=1*msg.payload.x/msg.payload.y;
    break;
  default:
   
}

msg.payload="result :"+result+"/ x :"+msg.payload.x+"/ y :"+msg.payload.y;
return msg;
```