API バックエンドを作成しました。
@ApiMethod(name = "create", path = "properties", httpMethod = HttpMethod.POST)
public void create(RealEstatePropertyAPI property, User user)
throws Exception {
}
次のデータ モデルを使用します。
public class RealEstatePropertyAPI {
private Long id;
private String name;
private AddressAPI address;
public RealEstatePropertyAPI() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public AddressAPI getAddress() {
return address;
}
public void setAddress(AddressAPI address) {
this.address = address;
}
}
public class AddressAPI {
private Long id;
private String street;
private String city;
private String state;
private String zip;
private String country;
public AddressAPI() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
次API Explorer
のリクエストで動作します:
POST http://localhost:8888/_ah/api/realestate/v1/properties
Content-Type: application/json
X-JavaScript-User-Agent: Google APIs Explorer
{
"name": "test",
"address": {
"city": "DC"
}
}
ただし、Angular JS
クライアントを使用する場合、RealEstatePropertyAPI
インスタンスは作成されますが、フィールドは入力されません (all null
)。リクエストは次のとおりです。
[{"jsonrpc":"2.0","id":"gapiRpc","method":"realestate.create","params":{"resource":"{\"name\": \"Test\",\"address\": { \"street\": \"White House\"}}"},"apiVersion":"v1"}]
JS 呼び出し:
var x = '{"name": "Test","address": { "street": "White House"}}';
gapi.client.realestate.create({"resource": x}).execute(function(resp) {
console.log(resp);
});