Sonatype Security REST API

C Client Library

Created Jun 15, 2010 8:01:58 AM.

Introduction

The C module generates the source code for the ANSI-C-compatible data structures 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 C source code depends on the XML Reader API and the XML Writer API as well as the <time.h>, <string.h>, and <stdlib.h> C standard libraries.

REST XML Example

#include <security-rest-api.c> //... xmlTextWriterPtr writer = ...; //set up the writer to the url. security_rest_api_ns0_userResourceRequest *request_element = ...; xmlTextReaderPtr reader = ...; //set up the reader to the url. security_rest_api_ns0_userResourceResponse *response_element = ...; //set up the security_rest_api_ns0_userResourceRequest... xml_write_security_rest_api_ns0_userResourceRequest(writer, request_element); response_element = xml_read_security_rest_api_ns0_userResourceResponse(reader); //handle the response as needed... //free the security_rest_api_ns0_userResourceRequest free_security_rest_api_ns0_userResourceRequest(request_element); //free the security_rest_api_ns0_userResourceResponse free_security_rest_api_ns0_userResourceResponse(response_element);

file size
security-rest-api.c 552.99K

.NET Client Library

Created Jun 15, 2010 8:02:00 AM for .NET 2.0.

Introduction

The .NET client-side library defines the classes that can be (de)serialized to/from XML. This is useful for accessing the REST endpoints that are published by this application.

REST Example

//read a resource from a REST url Uri uri = new Uri(...); XmlSerializer s = new XmlSerializer( typeof( UserResourceResponse ) ); //Create the request object WebRequest req = WebRequest.Create(uri); WebResponse resp = req.GetResponse(); Stream stream = resp.GetResponseStream(); TextReader r = new StreamReader( stream ); UserResourceResponse order = (UserResourceResponse) s.Deserialize( r ); //handle the result as needed...

This bundle contains C# source code.

file size
security-rest-api-dotnet.zip 4.17K

JAX-WS Client Library (Java 5+)

Created Jun 15, 2010 8:02:03 AM for Java (Version 5+).

Introduction

The JAX-WS client-side library is used to provide the set of Java objects that can be serialized to/from XML using JAXB. This is useful for accessing the REST endpoints that are published by this application.

REST Example (Raw JAXB)

java.net.URL url = new java.net.URL(baseURL + "/users"); JAXBContext context = JAXBContext.newInstance( UserResourceResponse.class, UserResourceRequest.class ); java.net.URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.connect(); Unmarshaller unmarshaller = context.createUnmarshaller(); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(userResourceRequest, connection.getOutputStream()); UserResourceResponse result = (UserResourceResponse) unmarshaller.unmarshal( connection.getInputStream() ); //handle the result as needed...

REST Example (Jersey client)

com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(); UserResourceResponse result = client.resource(baseUrl + "/users") .entity(userResourceRequest) .post(UserResourceResponse.class); //handle the result as needed...

Files

file size description
security-rest-api-client.jar 32.57K The binaries for the JAX-WS client library.
security-rest-api-client-sources.jar 22.66K The sources for the JAX-WS client library.

Objective C Client Library

Created Jun 15, 2010 8:01:58 AM.

Introduction

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.

REST XML Example

#include <security-rest-api.h> //... SECURITY_REST_APINS0UserResourceRequest *requestElement = [[SECURITY_REST_APINS0UserResourceRequest alloc] init]; NSData *requestData; //data holding the XML for the request. SECURITY_REST_APINS0UserResourceResponse *responseElement; NSData *responseData; //data holding the XML from the response. NSURL *baseURL = ...; //the base url including the host and subpath. NSURL *url = [NSURL URLWithString: @"/users" relativeToURL: baseURL]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; NSURLResponse *response = nil; NSError *error = NULL; [request setHTTPMethod: @"POST"]; [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; //set up the SECURITY_REST_APINS0UserResourceRequest... requestData = [requestElement writeToXML]; [request setHTTPBody: requestData]; //this example uses a synchronous request, //but you'll probably want to use an asynchronous call responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; SECURITY_REST_APINS0UserResourceResponse *responseElement = [SECURITY_REST_APINS0UserResourceResponse readFromXML: responseData]; [responseElement retain]; //handle the response as needed...

Files

file size description
security-rest-api.h 34.30K
security-rest-api.m 421.35K

Ruby Client Library

Created Jun 15, 2010 8:01:58 AM for Ruby.

Introduction

The Ruby client-side library defines the Ruby classes that can be (de)serialized to/from JSON. This is useful for accessing the REST endpoints that are published by this application, but only those that produce a JSON representation of their resources (content type "application/json").

This library leverages the Ruby JSON Implementation, which is required in order to use this library.

JSON REST Example

require 'net/https' require 'uri' //... //read a resource from a REST url url = URI.parse("...") request = Net::HTTP::Post.new(url.request_uri) input = UserResourceRequest.new //set up the UserResourceRequest... request.body = input.to_json request['Content-Type'] = "application/json" http = Net::HTTP.new(url.host, url.port) //set up additional http stuff... res = http.start do |ht| ht.request(request) end result = UserResourceResponse.from_json(JSON.parse(res.body)) //handle the result as needed...

file size
security-rest-api.rb 47.77K

Home

REST Endpoints

XML Data Elements

XML Data Types