resty icon indicating copy to clipboard operation
resty copied to clipboard

RFC: create client let us choice not much more middleware.

Open 0x010 opened this issue 5 years ago • 1 comments

func createClient(hc *http.Client) *Client {
	if hc.Transport == nil {
		hc.Transport = createTransport(nil)
	}

	c := &Client{ // not setting lang default values
		QueryParam:         url.Values{},
		FormData:           url.Values{},
		Header:             http.Header{},
		Cookies:            make([]*http.Cookie, 0),
		RetryWaitTime:      defaultWaitTime,
		RetryMaxWaitTime:   defaultMaxWaitTime,
		JSONMarshal:        json.Marshal,
		JSONUnmarshal:      json.Unmarshal,
		jsonEscapeHTML:     true,
		httpClient:         hc,
		debugBodySizeLimit: math.MaxInt32,
		pathParams:         make(map[string]string),
	}

	// Logger
	c.SetLogger(createLogger())

	// default before request middlewares
	c.beforeRequest = []RequestMiddleware{
		parseRequestURL,
		parseRequestHeader,
		parseRequestBody,
		createHTTPRequest,
		addCredentials,
	}

	// user defined request middlewares
	c.udBeforeRequest = []RequestMiddleware{}

	// default after response middlewares
	c.afterResponse = []ResponseMiddleware{
		responseLogger,
		parseResponseBody,
		saveResponseIntoFile,
	}

	return c
}

the current createClient seems abit heavy with much more Middleware.

Please allow use choice which middleware can been used.

0x010 avatar Jun 02 '20 00:06 0x010

@0x010 Thanks for reaching out with your thoughts. I would like to understand the viewpoint of bit heavy.

From the design of resty, every mentioned middleware is needed otherwise the resty library will not work :(
The only thing which stands out/out of place is saveResponseIntoFile.

May I know the issue you're facing?

jeevatkm avatar Sep 04 '20 06:09 jeevatkm