本文整理汇总了TypeScript中restify.createJsonClient函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createJsonClient函数的具体用法?TypeScript createJsonClient怎么用?TypeScript createJsonClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createJsonClient函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getConfigObject
/**
* Retrieves the application from the api.
* @param {IOptions} options The initialization options.
* @param {string} objectId The config object id.
* @return {Promise<ConfigObjectWrapper>} A promise of the config object.
*/
public static async getConfigObject(options: IOptions, objectId: string): Promise<ConfigObjectWrapper> {
Logger.log.debug("ApiClient.getConfigObject: start");
// check the bearer token before making the call
Logger.log.debug(`ApiClient.getConfigObject: Checking bearer token.`);
await ApiClient.checkBearerToken(options);
// initialise the restify client.
let client: restify.Client = restify.createJsonClient(ApiClient.getRestifyOptions(options));
let path: string = `/${options.subscription}/configuration/${options.application}/${objectId}/${options.environment}`;
Logger.log.debug("ApiClient.getConfigObject: Calling API", { url: options.url }, { path: path });
return new Promise<ConfigObjectWrapper>(
function(
resolve: (value: ConfigObjectWrapper) => void,
reject: (reason: Error) => void): void {
client.get(
path,
function(err: Error, req: restify.Request, res: restify.Response, obj: ConfigObjectWrapper): void {
if (err) {
Logger.log.error(err, `ApiClient.getConfigObject: Error getting configuration object '$objectId'.`);
let apiError: ApiError = new ApiError(
err.message, options.subscription, options.application, objectId, options.environment);
reject(apiError);
} else {
Logger.log.debug("ApiClient.getConfigObject: Configuration object wrapper received.", { data: obj });
resolve(obj);
}
});
});
}
示例2: getApplication
/**
* Retrieves the application from the api.
* @param {IOptions} options The initialization options.
* @return {Promise<ClocoApp>} A promise of the application.
*/
public static async getApplication(options: IOptions): Promise<ClocoApp> {
Logger.log.debug("ApiClient.getApplication: start");
// check the bearer token before making the call
Logger.log.debug(`ApiClient.getApplication: Checking bearer token.`);
await ApiClient.checkBearerToken(options);
// initialise the restify client.
let client: restify.Client = restify.createJsonClient(ApiClient.getRestifyOptions(options));
let path: string = `/${options.subscription}/applications/${options.application}`;
Logger.log.debug("ApiClient.getApplication: Calling API", { url: options.url }, { path: path });
return new Promise<ClocoApp>(
function(
resolve: (value: ClocoApp) => void,
reject: (reason: Error) => void): void {
client.get(
path,
function(err: Error, req: restify.Request, res: restify.Response, obj: ClocoApp): void {
if (err) {
Logger.log.error(err, "ApiClient.getApplication: Error getting application.");
let apiError: ApiError = new ApiError(err.message, options.subscription, options.application);
reject(apiError);
} else {
Logger.log.debug("ApiClient.getApplication: Application received.", { data: obj });
resolve(obj);
}
});
});
}
示例3: getAccessTokenFromClientCredentials
/**
* Refreshes the bearer token.
* @param {IOptions} options The initialization options.
* @return {Promise<AccessTokenResponse>} A promise of the access token.
*/
private static async getAccessTokenFromClientCredentials(options: IOptions): Promise<AccessTokenResponse> {
Logger.log.debug("ApiClient.getAccessTokenFromClientCredentials: start");
// initialise the restify client.
let client: restify.Client = restify.createJsonClient(ApiClient.getRestifyOptions(options, "basic"));
let path: string = `/oauth/token`;
let body: TokenRequest = new TokenRequest();
body.grant_type = "client_credentials";
Logger.log.debug("ApiClient.getAccessTokenFromClientCredentials: Calling API", { url: options.url }, { path: path });
return new Promise<AccessTokenResponse>(
function(
resolve: (value: AccessTokenResponse) => void,
reject: (reason: Error) => void): void {
client.post(
path,
body,
function(err: Error, req: restify.Request, res: restify.Response, obj: AccessTokenResponse): void {
if (err) {
Logger.log.error(err, "ApiClient.getAccessTokenFromClientCredentials: Error getting access token.");
reject(err);
} else {
Logger.log.debug("ApiClient.getAccessTokenFromClientCredentials: Access token response received.");
resolve(obj);
}
});
});
}
示例4: putConfigObject
/**
* Writes the config object to the server.
* @param {IOptions} options The options.
* @param {string} objectId The object Id.
* @param {any} body The item to write.
* @return {Promise<ConfigObjectWrapper>} A promise of the work completing.
*/
public static async putConfigObject(options: IOptions, objectId: string, body: any): Promise<ConfigObjectWrapper> {
Logger.log.debug("ApiClient.putConfigObject: start");
// check the bearer token before making the call
Logger.log.debug(`ApiClient.putConfigObject: Checking bearer token.`);
await ApiClient.checkBearerToken(options);
// initialise the restify client.
let client: restify.Client;
let parseResponse: boolean = false;
if (typeof body === "string") {
Logger.log.debug("ApiClient.putConfigObject: creating string client.");
client = restify.createStringClient(ApiClient.getRestifyOptions(options));
parseResponse = true;
} else {
Logger.log.debug("ApiClient.putConfigObject: creating JSON client.");
client = restify.createJsonClient(ApiClient.getRestifyOptions(options));
}
let path: string = `/${options.subscription}/configuration/${options.application}/${objectId}/${options.environment}`;
Logger.log.debug("ApiClient.putConfigObject: Calling API", { url: options.url }, { path: path });
return new Promise<ConfigObjectWrapper>(
function(
resolve: (value: ConfigObjectWrapper) => void,
reject: (reason: Error) => void): void {
client.put(
path,
body,
function(err: Error, req: restify.Request, res: restify.Response, obj: any): void {
if (err) {
Logger.log.error(err, "ApiClient.putConfigObject: Error writing data for configuration object '$objectId'.");
let apiError: ApiError = new ApiError(
err.message, options.subscription, options.application, objectId, options.environment);
reject(apiError);
} else {
if (parseResponse) {
obj = JSON.parse(obj);
}
Logger.log.debug("ApiClient.putConfigObject: Success response received.", { data: obj });
resolve(obj);
}
});
});
}
示例5: provision
function provision(marathonUrl: string, brokerName: string) {
const command = `node ${common.serviceBrokerContainerPath}`;
const appId = "/continuum/" + brokerName;
const json = marathonJson(appId, "hausdorff/ctest", command, 1, 8090);
// Add broker to registry. This will error out if we already have a broker
// with that name in the registry.
add(brokerName, marathonUrl);
// Attempt to provision with Marathon.
const client = restify.createJsonClient({ url: marathonUrl });
client.post(
marathonUrl + "/v2/apps",
json,
(err, req, res) => {
if (err) {
// Clean up after ourselves.
console.log(err);
rm(brokerName);
}
});
}
示例6: function
route.spec.path === '/some/path';
route.spec.path === /\/some\/path\/.*/;
route.spec.versions === ['v1'];
restify.auditLogger({ log: () => { } })(req, res, route, err);
});
(restify as any).defaultResponseHeaders = function(this: restify.Request, data: any) {
this.header('Server', 'helloworld');
};
(restify as any).defaultResponseHeaders = false;
// RESTIFY Client Tests
let client = restify.createJsonClient({
url: 'https://api.us-west-1.joyentcloud.com',
version: '*'
});
client = restify.createStringClient({
accept: "test",
connectTimeout: 30,
dtrace: {},
gzip: {},
headers: {},
log: {},
retry: {},
signRequest: () => { },
url: "",
userAgent: "",
version: ""
});
示例7:
// Set up front door.
const FrontDoorPort = 8000;
const FrontDoorUrl: string = "http://127.0.0.1" + ":" + FrontDoorPort;
var frontdoor = restify.createServer();
frontdoor.get('/api/test', (req,res,next) => {
var keyToLookup = { key: "your_favorite_key" }
continuum.forward(
continuum.cacheStage,
keyToLookup,
(continuum, stage, state) => stage.getDataAndProcess(continuum, stage, state));
res.end();
});
frontdoor.listen(FrontDoorPort);
const client = restify.createJsonClient({
url: FrontDoorUrl,
version: '*'
});
setTimeout(() => {
client.get("/api/test", (err, req, res) => {
// TODO: verify the thingWasProcessed member actually is true.
});
},
250);
// import chai = require('chai');
// var expect = chai.expect;
// describe('Test experimental Continuum API', () => {