Skip to content
Snippets Groups Projects
Commit 9b74ab10 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Edit remote doctype doc

parent e1957bcf
No related branches found
No related tags found
No related merge requests found
Pipeline #14856 passed
......@@ -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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment