Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update samples #336

Merged
merged 18 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ samples/*.js
samples/*.txt
test/**/*.js
test/**/testoutput.txt
npm-debug.log
npm-debug.log
build
7 changes: 2 additions & 5 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ target.buildtest = function() {
}

target.samples = function () {
pushd('samples');
run('npm install ../_build');
run('tsc');
run('node samples.js');
pushd('samples/basic');
run('npm install');
run('npm run react');
run('npm start');
popd();
console.log('done');
}
Expand Down
2 changes: 1 addition & 1 deletion samples/common.ts → samples/basic/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import http = require("http");
import * as http from "http";
import * as restm from 'typed-rest-client/RestClient';

// using httpbin.org.
Expand Down
1 change: 0 additions & 1 deletion samples/handlers.ts → samples/basic/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as hm from 'typed-rest-client/Handlers'
import * as cm from './common';
import * as httpm from 'typed-rest-client/HttpClient';

export async function run() {
cm.banner('Handler Samples');
Expand Down
6 changes: 3 additions & 3 deletions samples/http.ts → samples/basic/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export async function run() {
proxyUrl: cm.getEnv('PROXY_URL'),
proxyUsername: cm.getEnv('PROXY_USERNAME'),
proxyPassword: cm.getEnv('PROXY_PASSWORD'),
proxyBypassHosts: cm.getEnv('PROXY_BYPASS_HOSTS') ? cm.getEnv('PROXY_BYPASS_HOSTS').split(', ') : null
proxyBypassHosts: cm.getEnv('PROXY_BYPASS_HOSTS') ? cm.getEnv('PROXY_BYPASS_HOSTS').split(', ') : undefined
}
if (proxySettings.proxyUrl) {
httpc = new httpm.HttpClient('vsts-node-api', null, { proxy: proxySettings });
httpc = new httpm.HttpClient('vsts-node-api', undefined, { proxy: proxySettings });
body = await (await httpc.get('https://httpbin.org/get')).readBody();
cm.outputHttpBinResponse(body);
}
Expand All @@ -51,7 +51,7 @@ export async function run() {
// Http get request disabling redirects
//
cm.heading('get request disabling redirects');
httpc = new httpm.HttpClient('vsts-node-api', null, { allowRedirects: false });
httpc = new httpm.HttpClient('vsts-node-api', undefined, { allowRedirects: false });
res = await httpc.get("http://httpbin.org/redirect-to?url=" + encodeURIComponent("http://httpbin.org/get"))
body = await res.readBody();
cm.outputHttpBinResponse(body, res.message);
Expand Down
10 changes: 10 additions & 0 deletions samples/basic/httpClientStreamSample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"args": {},
"headers": {
"Host": "httpbin.org",
"User-Agent": "vsts-node-api",
"X-Amzn-Trace-Id": "Root=1-62d7a07a-61d28ace3597cb037f8ec7d2"
},
"origin": "37.252.93.218",
"url": "https://httpbin.org/get"
}
218 changes: 218 additions & 0 deletions samples/basic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions samples/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "typed-rest-client-basic-samples",
"version": "1.0.0",
"description": "Typed Rest Client Basic Samples",
"private": true,
"dependencies": {
"typed-rest-client": "file:../../_build"
},
"devDependencies": {
"ts-node": "^10.9.1",
"typescript": "^2.4.2"
},
"scripts": {
"start": "ts-node samples.ts"
},
"author": "Microsoft Corporation",
"license": "MIT"
}
10 changes: 4 additions & 6 deletions samples/rest.ts → samples/basic/rest.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import * as rm from 'typed-rest-client/RestClient';
import * as fs from 'fs';
import * as path from 'path';
import * as cm from './common';

let baseUrl: string = 'https://httpbin.org';
let restc: rm.RestClient = new rm.RestClient('rest-samples',
let restc: rm.RestClient = new rm.RestClient('rest-samples',
baseUrl);

export async function run() {

try {
cm.banner('Rest Samples');

//
// Get Resource: strong typing of resource(s) via generics.
// Get Resource: strong typing of resource(s) via generics.
// In this case httpbin.org has a response structure
// response.result carries the resource(s)
//
Expand All @@ -31,7 +29,7 @@ export async function run() {
let hello: HelloObj = <HelloObj>{ message: "Hello World!" };
let options: rm.IRequestOptions = cm.httpBinOptions();

cm.heading('create rest obj');
cm.heading('create rest obj');
let hres: rm.IRestResponse<HelloObj> = await restc.create<HelloObj>('/post', hello, options);
console.log(hres.result);

Expand Down
2 changes: 1 addition & 1 deletion samples/samples.ts → samples/basic/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function run() {
catch (err) {
console.error('Failed');
console.error(err.message);
}
}
}

run();
File renamed without changes.
Loading