com.webcohesion.enunciate.modules.objc_client.library_description.fmt Maven / Gradle / Ivy
[#ftl]
[#-- @ftlvariable name="resource_method" type="java.lang.String" --]
[#-- @ftlvariable name="resource_url" type="java.lang.String" --]
[#-- @ftlvariable name="slug" type="java.lang.String" --]
[#-- @ftlvariable name="filename" type="java.lang.String" --]
[#-- @ftlvariable name="input_element_name" type="java.lang.String" --]
[#-- @ftlvariable name="output_element_name" type="java.lang.String" --]
The Objective C module generates the source code for the Objective C classes and (de)serialization
functions that can be used in conjunction with libxml2 to (de)serialize
the REST resources as they are represented as XML data.
The generated Objective C source code depends on the XML Reader API
and the XML Writer API as well as the base OpenStep foundation classes.
[#if output_element_name??]
Objective C Example
#import <${slug}.h>
//...
[#if input_element_name??]
${input_element_name} *requestElement = [[${input_element_name} alloc] init];
NSData *requestData; //data holding the XML for the request.
[/#if]
${output_element_name} *responseElement;
NSData *responseData; //data holding the XML from the response.
NSURL *baseURL = ...; //the base url including the host and subpath.
NSURL *url = [NSURL URLWithString: @"${resource_url}" relativeToURL: baseURL];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSURLResponse *response = nil;
NSError *error = NULL;
[request setHTTPMethod: @"${resource_method}"];
[#if input_element_name??]
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
//set up the ${input_element_name}...
requestData = [requestElement writeToXML];
[request setHTTPBody: requestData];
[/#if]
//this example uses a synchronous request,
//but you'll probably want to use an asynchronous call
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
${output_element_name} *responseElement = [${output_element_name} readFromXML: responseData];
[responseElement retain];
//handle the response as needed...
[/#if]
© 2015 - 2025 Weber Informatics LLC | Privacy Policy