From 9b74ab101040c52d923cdf0f7b869c27521e3f29 Mon Sep 17 00:00:00 2001
From: "guilhem.carron" <gcarron@grandlyon.com>
Date: Wed, 7 Jul 2021 15:28:58 +0200
Subject: [PATCH] Edit remote doctype doc

---
 .../project_architecture/remote_doctypes.md   | 51 +++++++++++++++----
 1 file changed, 42 insertions(+), 9 deletions(-)

diff --git a/docs/ecolyo/project_architecture/remote_doctypes.md b/docs/ecolyo/project_architecture/remote_doctypes.md
index 1332fdd..afb3011 100644
--- a/docs/ecolyo/project_architecture/remote_doctypes.md
+++ b/docs/ecolyo/project_architecture/remote_doctypes.md
@@ -4,7 +4,7 @@ The remote doctype should be created in the cozy repo : [https://github.com/cozy
 
 ## Remote doctype org.ecolyo.usage
 
-To create the remote the first create a folder named 'org.ecolyo.usage' and then add a file name request in the folder.
+To create the remote the first create a folder named 'org.ecolyo.usage' and then add a file named _request_ in the folder.
 
 Here is the structure of the file:
 
@@ -17,7 +17,7 @@ Content-Type: application/json
 
 ## Local remote doctype
 
-As the doctype if not yet avaible on cozy repo, we first need to test it on local. For that we can use the *—doctypes* command in the cozy-stack serve and use it to point to a local repo. 
+As the doctype if not yet avaible on cozy repo, we first need to test it on local. For that we can use the _—doctypes_ command in the cozy-stack serve and use it to point to a local repo.
 
 Here are the step:
 
@@ -31,7 +31,7 @@ Content-Type: application/json
 {{data}}
 ```
 
-- add the *—doctypes* command in the "docker/cozy-app-dev-with-app.sh" file and also the *-remote-allow-custom-port* flag
+- add the _—doctypes_ command in the "docker/cozy-app-dev-with-app.sh" file and also the _-remote-allow-custom-port_ flag
 
 ```bash
 ${COZY_STACK_PATH} serve --allow-root \
@@ -51,12 +51,22 @@ ${COZY_STACK_PATH} serve --allow-root \
 
 ```yaml
 remote_assets:
-    ecolyo-usage: http://cozy.tools:8080/remote/org.ecolyo.usage/
+  ecolyo-usage: http://cozy.tools:8080/remote/org.ecolyo.usage/
 ```
 
-- build the docker image: docker build .
-- tag the image to [registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env](http://registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env)
-- add the following command to winstack script in the package.json:
+- Go to the docker folder in the project root
+
+```
+cd docker
+```
+
+- build the docker image and tag it to [registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env](http://registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env):
+
+```
+docker build . -t registry.forge.grandlyon.com/web-et-numerique/llle_project/ecolyo/cozy-env
+```
+
+- Then add the following command to winstack script in the package.json:
 
 ```yaml
 -v $PWD/cozy-doctypes:/data/cozy-doctypes
@@ -68,7 +78,7 @@ remote_assets:
 yarn winstack
 ```
 
-- Change the content request param in io.cozy.doctypes/org.ecolyo.usage using the db tool ([http://localhost:5984/_utils](http://localhost:5984/_utils)):
+- Change the content request param in io.cozy.doctypes/org.ecolyo.usage using the db tool ([http://localhost:5984/\_utils](http://localhost:5984/_utils)):
 
 ```bash
 "request": "POST https://API_URL\nContent-Type: application/json\n\n{{data}}",
@@ -95,4 +105,27 @@ const result = await client
     .fetchJSON('POST', '/remote/org.ecolyo.usage', {
       JSON.stringify(indicator),
     })
-```
\ No newline at end of file
+```
+
+## Passing parameters to a remote doctype
+
+In order to pass parameters to a remote doctypes such as query paramaters or headers, you need to process the following way :
+
+You can pass header directly under the URL in the _request_ file, such as Authorization or Content-Type headers.
+
+```bash
+GET https://API_URL/?q={queryParam}
+Authorization: Bearer {{secret_token}}
+Content-Type: application/json
+
+```
+
+When you call the remote doctype, you can directly pass the parameters to the doctype :
+
+```jsx
+const result = await client
+  .getStackClient()
+  .fetchJSON("GET", "/remote/org.ecolyo.usage/queryParam=yourParameter");
+```
+
+If you wanna know more about remote doctypes and how to store and use secret tokens, please refer to the official cozy documentation.
-- 
GitLab