RestletでのAnnotationの続き
日曜日にやっと時間がとれたのでRestletのAnnotationの続きを試してみた。
RestletのAnnotationはパラメータを指定できる。で、それってどのように動作するのか試してみた。
以下のコードを用意
public class DataInput extends ServerResource {
@Post ("txt")
public String represent(Representation entity) {
String str = getReference().getPath();
System.out.println( str );
return "Post:txt "+str;
}
@Post ("json")
public String representjson(Representation entity) {
String str = getReference().getPath();
System.out.println( str );
return "Post:json "+str;
}
}
Restクライアントでは、まずは以下のPythonコードを実行した。
response=request.post('http://192.168.1.62:8010/command/datain/temp", headers={'Content-Type':'text/plain'})
responseは Post:txt /command/datain/temp
次に以下を実行した。
response=request.post('http://192.168.1.62:8010/command/datain/temp",headers={'Content-Type':'application/json'})
responseは Post:json /command/datain/temp
つまり、同じPOSTでもContent-Typeで実行するコードを使い分けることができるわけだ。
これは便利な気がする。
« Bondで1日縛られた土曜日 | トップページ | RestletにBasic認証を構成してみた »
「ラズパイ日記」カテゴリの記事
- NEO-7M GPSモジュールが中国から届いた(2023.01.15)
- TNCアプリにおけるDemoduatorの動作確認(2023.01.09)
- AFSKでの復調について(2023.01.04)
- APRSでのNRZIについて備忘録(2023.01.02)
- pico_tnc 2200Hz(Space)でPhaseをずらす件の備忘録(2022.12.31)
コメント