Skip to content

Commit

Permalink
Merge pull request #20 from crshnburn/zosconnect-apis
Browse files Browse the repository at this point in the history
z/OS Connect apis
  • Loading branch information
crshnburn committed Apr 13, 2016
2 parents a1b4938 + 287594d commit 491c2a0
Show file tree
Hide file tree
Showing 8 changed files with 578 additions and 144 deletions.
166 changes: 109 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
- [Connecting to z/OS Connect](#connecting-to-zos-connect)
- [HTTPs Support](#https-support)
- [Basic Authentication](#basic-authentication)
- [Retrieve a list of services](#retrieve-a-list-of-services)
- [Get a service](#get-a-service)
- [Invoke a service](#invoke-a-service)
- [Get the request schema](#get-the-request-schema)
- [Get the response schema](#get-the-response-schema)
- [Get the status of the service](#get-the-status-of-the-service)
- [APIs](#apis)
- [Retrieve a list of APIs](#retrieve-a-list-of-apis)
- [Get an API](#get-an-api)
- [Call an API](#call-an-api)
- [Get the Swagger document for an API](#get-the-swagger-document-for-an-api)
- [Services](#services)
- [Retrieve a list of services](#retrieve-a-list-of-services)
- [Get a service](#get-a-service)
- [Invoke a service](#invoke-a-service)
- [Get the request schema](#get-the-request-schema)
- [Get the response schema](#get-the-response-schema)
- [Get the status of the service](#get-the-status-of-the-service)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -46,7 +52,7 @@ npm install zosconnect-node
```js
var ZosConnect = require('zosconnect-node');
var options = {
uri:'http://mainframe:8080'
uri:'http://mainframe:8080'
}
var zosconnect = new ZosConnect(options);
```
Expand All @@ -61,99 +67,145 @@ var caFile = path.resolve(__dirname, 'ca.pem');
var certFile = path.resolve(__dirname, 'cert.pem');
var keyFile = path.resolve(__dirname, 'key.pem');
var options = {
uri:'https://mainframe:9443',
ca: fs.readFileSync(caFile),
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
passphrase: 'passw0rd',
strictSSL: true
uri:'https://mainframe:9443',
ca: fs.readFileSync(caFile),
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
passphrase: 'passw0rd',
strictSSL: true
}
```

##### Basic Authentication
Add the authentication credentials to the options object.
```js
var options = {
uri: 'http://mainframe:9080',
auth: {
user: 'userId',
pass: 'password'
}
uri: 'http://mainframe:9080',
auth: {
user: 'userId',
pass: 'password'
}
}
```

#### Retrieve a list of services
#### APIs

##### Retrieve a list of APIs

```js
zosconnect.getApis(function(error, apis){
console.log(apis);
})
```

##### Get an API

```js
zosconnect.getApi('healthApi', function(error, api){
console.log(api);
})
```

##### Call an API

```js
zosconnect.getApi('healthApi', function(error, api){
api.invoke('patient/12345', 'GET', null, function(error, response, body){
if(error){
console.log(error);
} else if(response.statusCode != 200) {
console.log('Invoke failed with respCode = ' + response.statusCode);
} else {
console.log(body);
}
})
})
```

##### Get the Swagger document for an API

```js
zosconnect.getApi('healthApi', function(error, api){
api.getApiDoc(function(error, swagger){
console.log(swagger);
})
})
```

#### Services

##### Retrieve a list of services

```js
zosconnect.getServices(function(error, services){
console.log(services);
console.log(services);
});
```

#### Get a service
##### Get a service

```js
zosconnect.getService('dateTimeService', function(error, service){
console.log(service);
//normally this would then go on and work with the service
console.log(service);
//normally this would then go on and work with the service
});
```

#### Invoke a service
##### Invoke a service

```js
zosconnect.getService('dateTimeService', function(error, service){
service.invoke({input:'data'}, function(error, response, body){
if(error){
console.log(error);
} else if(response.statusCode != 200) {
console.log('Invoke failed with respCode = ' + response.statusCode);
} else {
console.log(body);
}
});
service.invoke({input:'data'}, function(error, response, body){
if(error){
console.log(error);
} else if(response.statusCode != 200) {
console.log('Invoke failed with respCode = ' + response.statusCode);
} else {
console.log(body);
}
});
});
```

#### Get the request schema
##### Get the request schema

```js
zosconnect.getService('dateTimeService', function(error, service){
service.getRequestSchema(function(error, schema){
if(error){
console.log(error);
} else {
console.log(schema);
}
});
service.getRequestSchema(function(error, schema){
if(error){
console.log(error);
} else {
console.log(schema);
}
});
});
```

#### Get the response schema
##### Get the response schema

```js
zosconnect.getService('dateTimeService', function(error, service){
service.getResponseSchema(function(error, schema){
if(error){
console.log(error);
} else {
console.log(schema);
}
});
service.getResponseSchema(function(error, schema){
if(error){
console.log(error);
} else {
console.log(schema);
}
});
});
```

#### Get the status of the service
##### Get the status of the service

```js
zosconnect.getService('dateTimeService', function(error, service){
service.getStatus(function(error, status){
if(error){
console.log(error);
} else {
console.log(status);
}
});
service.getStatus(function(error, status){
if(error){
console.log(error);
} else {
console.log(status);
}
});
});
```

Expand Down
59 changes: 59 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright 2016 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var request = require('request');
var extend = require('extend');

module.exports = function (options, apiName, basePath, documentation) {
this.options = options;
this.apiName = apiName;
this.basePath = basePath;
this.documentation = documentation;

this.getApiDoc = function (type, callback) {
var options = {};
var documentationUri = documentation[type];
if (documentationUri == undefined) {
callback(new Error('Documentation not available'), null);
} else {
options = extend(options, this.options);
options.uri = documentationUri;
request.get(options, function (error, response, body) {
if (error != null) {
callback(error, null);
} else if (response.statusCode != 200) {
callback(new Error('Unable to retrieve Swagger document (' + response.statusCode + ')'),
null);
} else {
callback(null, body);
}
});
}
};

this.invoke = function (resource, method, content, callback) {
var options = {};
options = extend(options, this.options);
options.uri = basePath + '/' + resource;
options.method = method;
if (content != null) {
options.body = content;
}

options.json = true;
request(options, callback);
};
};
Loading

0 comments on commit 491c2a0

Please sign in to comment.