Hello World Backend
Lembas Hello World example
If you followed the steps and generated the source code, you notice that it only contains endpoint address and a base class. You need artifacts and enpoints to be able to generate code and make request to your backend.
Endpoints
Create a package in your project com.happyblueduck.enpoints and add your first endpoint by extending LembasRequest...
package com.happyblueduck.enpoints;
import com.happyblueduck.lembas.core.LembasResponse;
import com.happyblueduck.lembas.core.UtilSerializeException;
import com.happyblueduck.lembas.processing.LembasActionContext;
import com.happyblueduck.lembas.processing.LembasProcessRequest;
import com.happyblueduck.lembas.processing.RequestProcessException;
public String requestParamString;
public int requestParamInt;
public double requestParamDouble;
public class HelloWorldRequest extends LembasProcessRequest {
@Override
public LembasResponse process(LembasActionContext lembasActionContext) throws RequestProcessException, UtilSerializeException {
HelloWorldResponse response = new HelloWorldResponse();
response.message = "Goodbye, cruel world";
return response;
}
}
...and LembasResponse
package com.happyblueduck.enpoints;
import com.happyblueduck.lembas.core.LembasResponse;
public class HelloWorldResponse extends LembasResponse {
public String message;
}
Artifacts
We can also add an artifact to our backend. Create a package named com.happyblueduck.artifact and add an artifact by extending LembasObject:
package com.happyblueduck.artifacts;
import com.happyblueduck.lembas.core.LembasObject
import java.util.Date;
import java.util.ArrayList;
public class HelloArtifact extends LembasObject{
// lembas supports primiteves
public String sstring;
public Double ddouble;
public Long llong;
public Date ddate;
// and arrays
public ArrayList<String> aarray;
// and array of lembasObjects
public ArrayList<HelloArtifact> artifacst;
}
Now that we have our first endpoint, we should update our Configuration:
@Override
public void init() throws ServletException {
//service name and servlet url-mapping should match
Config.serviceName = "Arwen";
Config.version = "1.0";
Config.HOST_URL = http://localhost";
Config.HOST_PORT = "8080"
// endpoints and artifacts are added by packages
Config.addEndpoint("com.happyblueduck.enpoints");
}
If you generate the iOS source code now from http://localhost:8080/lembas?target=objc, you will see HelloRequest
, HelloResponse
and HelloArtifact
classes. You can now build an iOS application that use this service with Lembas-ios.
Updated less than a minute ago