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

[PROPOSAL] [Draft] Start PIMO as web service mock #37

Open
adrienaury opened this issue May 27, 2021 · 2 comments
Open

[PROPOSAL] [Draft] Start PIMO as web service mock #37

adrienaury opened this issue May 27, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@adrienaury
Copy link
Member

adrienaury commented May 27, 2021

Start PIMO with a backend web service as source for mocks.

Related to #40 and #15

Find a way to define routes. Possibly use the mmock project (https://github.com/jmartin82/mmock/)

@adrienaury adrienaury added the enhancement New feature or request label May 27, 2021
@adrienaury
Copy link
Member Author

adrienaury commented Jun 1, 2021

Drafts

$ echo '{"userid": "6022955c5e70a4fbbd9fcfae"}' | pimo mock get https://www.data.gouv.fr/api/1/users/{{.userid}}/
{"about": null,"active": true,"avatar": null,"avatar_thumbnail": null,"email": null,"first_name": "coralie","id": "6022955c5e70a4fbbd9fcfae","last_name": "spillebout","metrics": {"datasets": 0,"followers": 0,"following": 0,"reuses": 0},"organizations": [],"page": "https://www.data.gouv.fr/fr/users/coralie-spillebout-1/","roles": [],"since": "2021-02-09T14:59:56.271000","slug": "coralie-spillebout-1","uri": "https://www.data.gouv.fr/api/1/users/coralie-spillebout-1/","website": null}
$ echo '{"userid": "6022955c5e70a4fbbd9fcfae"}' | pimo --serve 8080/mockservice mock get https://www.data.gouv.fr/api/1/users/{{.userid}}/
1:53PM INF Serving data on port 8080 and route '/mockservice'
$ echo '{"body": {"first_name": "john", "last_name": "snow"}}' | pimo mock post --body {{.body}} https://www.data.gouv.fr/api/1/users/
{"about": null,"active": true,"avatar": null,"avatar_thumbnail": null,"email": null,"first_name": "coralie","id": "6022955c5e70a4fbbd9fcfae","last_name": "spillebout","metrics": {"datasets": 0,"followers": 0,"following": 0,"reuses": 0},"organizations": [],"page": "https://www.data.gouv.fr/fr/users/coralie-spillebout-1/","roles": [],"since": "2021-02-09T14:59:56.271000","slug": "coralie-spillebout-1","uri": "https://www.data.gouv.fr/api/1/users/coralie-spillebout-1/","website": null}
$ pimo --serve 8080/mockservice mock post --body {{.body}} https://www.data.gouv.fr/api/1/users/
1:53PM INF Serving data on port 8080 and route '/mockservice'
$ cat routes.yml
routes:
  - name: /mockservice/api/1/users/:{userid}/
    method: get
    masking:
      - ...
  - name: /mockservice/api/1/users/
    method: post
    masking:
      - ...
$ pimo --serve 8080
1:53PM INF Serving data on port 8080

@adrienaury adrienaury changed the title [PROPOSAL] Start PIMO as web service mock [PROPOSAL][Draft] Start PIMO as web service mock Jun 3, 2021
@adrienaury adrienaury changed the title [PROPOSAL][Draft] Start PIMO as web service mock [PROPOSAL] [Draft] Start PIMO as web service mock Jun 3, 2021
@adrienaury
Copy link
Member Author

adrienaury commented Jan 30, 2024

Example 1 : Emulate fake web service

routes.yml

version: "1"
routes:
- name: api/users/:{userid}/
  method: get
  maskingfile: masking-user.yml

masking-user.yml

version: "1"
masking:
  - selector:
      jsonpath: "response.body.id"
    mask:
      add: "{{.params.url.userid}}"
  - selector:
      jsonpath: "response.body.name"
    masks:
      - add: "{{.params.url.userid}}"
      - hashInURI: "pimo://nameFR"
$ pimo mock --port 8080
listening on 0.0.0.0:8080
$ curl http://localhost:8080/api/users/1/
{"id":1, "name": "Geoffroy"}

Example 2 : Wrap existing web service

routes.yml

version: "1"
routes:
- name: api/users/:{userid}/
  method: get
  maskingfile: masking-user.yml

masking-user.yml

version: "1"
masking:
  - selector:
      jsonpath: "response"
    mask:
      http:
        url: "http://real-web-service/api/users/{{.params.url.userid}}/
        method: "get"
  - selector:
      jsonpath: "response.body.name"
    masks:
      - template: "{{.response.body.id}}"
      - hashInURI: "pimo://nameFR"
$ pimo mock --port 8080
listening on 0.0.0.0:8080
$ curl http://localhost:8080/api/users/1/
{"id":1, "name": "Geoffroy"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant