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

[TT-10538] Service Discovery support custom method and request body #5636

Open
cuongtd1301 opened this issue Oct 18, 2023 · 1 comment
Open

Comments

@cuongtd1301
Copy link

cuongtd1301 commented Oct 18, 2023

Is your feature request related to a problem? Please describe.

When using the service discovery with etcd, I utilize etcd v3 which only supports the POST method and requires a request body. However, Tyk only supports the GET method which is used by etcd v2.

Describe the solution you'd like

  • service_discovery: add method and body field
{
    "query_endpoint": "http://127.0.0.1:4001/v3/kv/range"
    "method" : "POST",
    "body": "{\"key\":\"AA==\",\"range_end\":\"AA==\"}"
}
  • ServiceDiscovery: add method and body field
type ServiceDiscovery struct {
	spec                *apidef.ServiceDiscoveryConfiguration
	isNested            bool
	isTargetList        bool
	endpointReturnsList bool
	portSeperate        bool
	dataPath            string
	parentPath          string
	portPath            string
	targetPath          string
	method              string
	body                string
}
  • func getServiceData: custom method and request body
func (s *ServiceDiscovery) getServiceData(method, requestURL, body string) (string, error) {
	req, err := http.NewRequest(method, requestURL, bytes.NewBuffer([]byte(body)))
	if err != nil {
		return "", err
	}
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return "", err
	}

	defer resp.Body.Close()
	contents, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}

	return string(contents), nil
}
@andyo-tyk andyo-tyk changed the title Service Discovery support custom method and request body [TT-10538] Service Discovery support custom method and request body Nov 15, 2023
@andyo-tyk
Copy link
Contributor

Hi @cuongtd1301,

Thanks for flagging this issue.

We're not actively looking at Service Discovery at the moment, but when we do then we will certainly take your idea into account.

If you want to try an implementation yourself, we welcome PRs from the Tyk community.

Thanks for supporting Tyk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants