From 3ada99e480680067bbe1a4b3166bac8adf0866ac Mon Sep 17 00:00:00 2001 From: camilner-hdr Date: Wed, 17 Jul 2024 11:45:52 +0100 Subject: [PATCH 1/5] Reordered the nav menu item for Using the Gateway. Added in a new page for "Making an authenticated request" --- mkdocs.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 130d2cd..29d8117 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -18,12 +18,13 @@ extra_css: nav: - Home: index.md + - Using the Gateway: + - Login: fe-login.md - Accessing Our APIs: - What is a Private App: private-app-what.md - Create a Private App: private-app-create.md - Manage a Private App: private-app-manage.md - - Using the Gateway: - - Login: fe-login.md + - Making an authenticated request: private-app-authenticated-request.md - Integrations: - HDR UK Datasets Integration: integrations-hdruk-datasets.md - Metadata: From f4d6f33005fcba39775c2afd66421c17afbf0eaa Mon Sep 17 00:00:00 2001 From: camilner-hdr Date: Wed, 17 Jul 2024 12:03:42 +0100 Subject: [PATCH 2/5] New "Using our APIs" section based on documentation, new folder for using-out-apis, and new file for making an authenticated request --- docs/using-our-apis/making-an-authenticated-request.md | 0 mkdocs.yml | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 docs/using-our-apis/making-an-authenticated-request.md diff --git a/docs/using-our-apis/making-an-authenticated-request.md b/docs/using-our-apis/making-an-authenticated-request.md new file mode 100644 index 0000000..e69de29 diff --git a/mkdocs.yml b/mkdocs.yml index 29d8117..26ca17a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,7 +24,8 @@ nav: - What is a Private App: private-app-what.md - Create a Private App: private-app-create.md - Manage a Private App: private-app-manage.md - - Making an authenticated request: private-app-authenticated-request.md + - Using our APIs: + - Making an authenticated request: using-our-apis/making-an-authenticated-request.md - Integrations: - HDR UK Datasets Integration: integrations-hdruk-datasets.md - Metadata: From 07fddc23d2d24a09cdf7cdfce0e1757d1ae54634 Mon Sep 17 00:00:00 2001 From: camilner-hdr Date: Wed, 17 Jul 2024 14:19:40 +0100 Subject: [PATCH 3/5] Implementation of page for making and authenticated request --- .../making-an-authenticated-request.md | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/docs/using-our-apis/making-an-authenticated-request.md b/docs/using-our-apis/making-an-authenticated-request.md index e69de29..0e97065 100644 --- a/docs/using-our-apis/making-an-authenticated-request.md +++ b/docs/using-our-apis/making-an-authenticated-request.md @@ -0,0 +1,117 @@ +# Making an authenticated request +To make an authenticated request to our API, you need to ensure that you have a Private App configured on the Gateway, and have taken note of the `app_id` and `client_id`. These credentials must be included in the headers of any API requests where you are managing data. + +## Code Examples +The code examples below demonstrate how to make an authenticated request to the Gateway API using a simple get request for a dataset. Please make sure you replace `YOUR_APP_ID` and `YOUR_CLIENT_ID` with the actual `app_id` and `client_id` you obtained when creating a Private App. + +You can also test our APIs from the Swagger documentation in the link below. +[https://api.healthdatagateway.org/api/documentation#/](https://api.healthdatagateway.org/api/documentation#/) + + +=== "CURL" + + ``` bash + curl -X GET "https://api.healthdatagateway.org/api/v1/datasets" \ + --header "x-application-id: " \ + --header "x-client-id: " + ``` + +=== " python " + + ``` python + import requests + + url = "https://api.healthdatagateway.org/api/v1/datasets" + headers = { + "x-application-id": , + "x-client-id": + } + + response = requests.get(url, headers) + print(response.json()) + + ``` + +=== " Node.js " + + ``` js + const axios - require('axios') + + const url = ; + const headers = { + "x-application-id": , + "x-client-id": + }; + + axios.get(url, {headers: headers}) + .then(response => ( + console.log(response.data); + )) + .catch(error => { + console.error(error); + }); + ``` + +=== " C++ " + + ``` cpp + #include + #include + + int main() { + CURL *curl; + CURLcode res; + + curl = surl_easy_init(); + if(curl){ + curl_easy_setopt(curl, CURLOPT_URL, "https://api.healthdatagateway.org/api/v1/datasets"); + + struct curl_slist *headers = NULL; + headers - curl_slist_append(headers, "x-application-id: "); + headers - curl_slist_append(headers, "x-client-id: "); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + + res = curl_easy_perform(curl); + + curl_slist_freee_all(headers); + curl_easy_cleanup(curl); + } + return 0 + } + ``` + +=== " Go " + + ``` go + package main + + import { + "ftm" + "io/ioutil" + "net/http" + } + + func main(){ + client := &http.Client{} + req, err := http.NewRequest("GET", "https://api.healthdatagateway.org/api/v1/datasets", nil) + if err != nil { + panic(err) + } + + req.Header.Add("x-application-id", ) + req.Header.Add("x-client-id", ) + + resp, err : client.Do(req) + if err != nil { + painc(err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.body) + if err != nil { + panic(err) + } + + ftm.Println(string(body)) + } + ``` \ No newline at end of file From 43031a8a0d90059059c45692b0f08084f057dba2 Mon Sep 17 00:00:00 2001 From: camilner-hdr Date: Wed, 17 Jul 2024 14:44:54 +0100 Subject: [PATCH 4/5] Typo correction for ftm => fmt in go example --- docs/using-our-apis/making-an-authenticated-request.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/using-our-apis/making-an-authenticated-request.md b/docs/using-our-apis/making-an-authenticated-request.md index 0e97065..eba5415 100644 --- a/docs/using-our-apis/making-an-authenticated-request.md +++ b/docs/using-our-apis/making-an-authenticated-request.md @@ -86,7 +86,7 @@ You can also test our APIs from the Swagger documentation in the link below. package main import { - "ftm" + "fmt" "io/ioutil" "net/http" } @@ -112,6 +112,6 @@ You can also test our APIs from the Swagger documentation in the link below. panic(err) } - ftm.Println(string(body)) + fmt.Println(string(body)) } ``` \ No newline at end of file From 8cbe7e0a47ffbf22ecfedc2696cd1c3de6dc5e04 Mon Sep 17 00:00:00 2001 From: camilner-hdr Date: Wed, 17 Jul 2024 14:45:56 +0100 Subject: [PATCH 5/5] Correction for cpp example, correctin surl to curl --- docs/using-our-apis/making-an-authenticated-request.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/using-our-apis/making-an-authenticated-request.md b/docs/using-our-apis/making-an-authenticated-request.md index eba5415..18347ca 100644 --- a/docs/using-our-apis/making-an-authenticated-request.md +++ b/docs/using-our-apis/making-an-authenticated-request.md @@ -62,7 +62,7 @@ You can also test our APIs from the Swagger documentation in the link below. CURL *curl; CURLcode res; - curl = surl_easy_init(); + curl = curl_easy_init(); if(curl){ curl_easy_setopt(curl, CURLOPT_URL, "https://api.healthdatagateway.org/api/v1/datasets");