Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Abstract.performRest Overload #316

Closed
dkelosky opened this issue Oct 29, 2019 · 3 comments
Closed

Abstract.performRest Overload #316

dkelosky opened this issue Oct 29, 2019 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dkelosky
Copy link
Contributor

AbstractRestClient.performRest() has been overloaded for streams and other options, but the method name is a bit more difficult to use now. Can this be overloaded to add an options object for the optional parms?

For example:

        return new this(session).performRest(resource, HTTP_VERB.GET, reqHeaders, undefined, responseStream,
            undefined, normalizeResponseNewLines, undefined, task);

It's a little more difficult to use the API having to know the positional places to specify undefined.

Perhaps a prototype like something like this would help API users:

    public performRest(resource: string, request: HTTP_VERB, reqHeaders?: any[], 
                       options: {writeData?: any,
                       responseStream?: Writable, requestStream?: Readable,
                       normalizeResponseNewLines?: boolean, normalizeRequestNewLines?: boolean,
                       task?: ITaskWithStatus
                       })

So the above example would look like:

        return new this(session).performRest(resource, HTTP_VERB.GET, reqHeaders, { responseStream,
            normalizeResponseNewLines, task});
@dkelosky dkelosky added enhancement New feature or request good first issue Good for newcomers labels Oct 29, 2019
dkelosky added a commit that referenced this issue Nov 1, 2019
Signed-off-by: Dan Kelosky <dkelosky@gmail.com>
@dkelosky
Copy link
Contributor Author

As a PoC, I have:

    /**
     * Overload function to perform the actual http REST call with appropriate user input using an option object (following angular's HTTPClient)
     * @param {IRestOptions} options
     * @memberof AbstractRestClient
     */
    public request(opts: IRestOptions) {

With, IRestOptions being:

/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import { HTTP_VERB } from "../types/HTTPVerb";
import { Writable, Readable } from "stream";
import { ITaskWithStatus } from "../../../../operations";

/**
 * Interface to performRest function
 * @export
 * @interface IRestOptions
 */
export interface IRestOptions {

    /**
     * URI for this request
     * @type {string}
     * @memberof IRestOptions
     */
    resource: string;

    /**
     * REST request type GET|PUT|POST|DELETE
     * @type {HTTP_VERB}
     * @memberof IRestOptions
     */
    request: HTTP_VERB;

    /**
     * Headers to include with request
     * @type {any[]}
     * @memberof IRestOptions
     */
    reqHeaders?: any[];

    /**
     * Data to write on this REST request
     * @type {*}
     * @memberof IRestOptions
     */
    writeData?: any;

    /**
     * Stream for incoming response data from the server. If specified, response data will not be buffered
     * @type {Writable}
     * @memberof IRestOptions
     */
    responseStream?: Writable;

    /**
     * Stream for outgoing request data to the server
     * @type {Readable}
     * @memberof IRestOptions
     */
    requestStream?: Readable;

    /**
     * true if you want newlines to be \r\n on windows
     * when receiving data from the server to responseStream. Don't set this for binary responses
     * @type {boolean}
     * @memberof IRestOptions
     */
    normalizeResponseNewLines?: boolean;

    /**
     * true if you want \r\n to be replaced with \n when sending
     * data to the server from requestStream. Don't set this for binary requests
     * @type {boolean}
     * @memberof IRestOptions
     */
    normalizeRequestNewLines?: boolean;

    /**
     * Task that will automatically be updated to report progress of upload or download to user
     * @type {ITaskWithStatus}
     * @memberof IRestOptions
     */
    task?: ITaskWithStatus;
}

ghost pushed a commit that referenced this issue Jan 14, 2020
Signed-off-by: Dan Kelosky <dkelosky@gmail.com>
@ghost
Copy link

ghost commented Mar 16, 2020

@dkelosky Can this be closed? Looks like it was addressed in #348

@dkelosky
Copy link
Contributor Author

Yes - Ill just do that here. Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant