22
33[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square )] ( http://makeapullrequest.com )
44
5- ** grit-requester-js ** is a javascript library to abstract requests to microservices built using Grit.
5+ ** grit-requester-python ** is a python library to abstract requests to microservices built using Grit.
66
77Features:
88
@@ -17,112 +17,80 @@ Features:
1717## ✨ Installation
1818
1919``` bash
20- npm install " https://github.com/not-empty/grit-requester-js/releases/download/v1.0.2/grit-requester-js-1.0.2.tgz "
20+ pip install grit_requester
2121```
2222
2323---
2424
2525## 🚀 Usage Example
2626
2727### Configure and do a request
28- ``` ts
29- import { GritRequester } from ' grit-requester-js' ;
30-
31- interface IUser {
32- id: string ;
33- name: string ;
34- email: string ;
35- }
36-
37- // configure grit requester
38- const ms = new GritRequester ({
39- baseUrl: ' http://localhost:8001' ,
40- token: process .env .SERVICE_TOKEN || ' ' ,
41- secret: process .env .SERVICE_SECRET || ' ' ,
42- context: process .env .SERVICE_CONTEXT || ' ' ,
43- });
44-
45- // doing a request
46- const result = await ms .request <{ id: string }>({
47- path: ' /user/add' ,
48- method: ' POST' ,
49- body: {
50- name: ' example' ,
51- email: ' example@example.com'
52- }
53- });
54-
28+ ``` python
29+ from grit_requester import GritService, GritConfig
30+
31+ # configure grit requester
32+ config = GritConfig(
33+ base_url = os.getenv(" SERVICE_BASE_URL" ),
34+ auth_url = os.getenv(" SERVICE_AUTH_URL" ),
35+ token = os.getenv(" SERVICE_TOKEN" ),
36+ secret = os.getenv(" SERVICE_SECRET" ),
37+ context = os.getenv(" SERVICE_CONTEXT" ),
38+ )
39+
40+ ms = GritService(config)
41+
42+ # doing a request
43+ resp = ms.request(
44+ " GET" ,
45+ " /user/list" ,
46+ )
5547```
5648
5749### Make crud requests from a domain
5850
5951Here you can call a domain passing the type and path to access the following base routers:
6052
61- | Path | Description |
62- | -----------------| -------------------------------------------|
63- | add | Create a new record |
64- | bulk | Fetch specific records by IDs |
65- | bulkAdd | Create up to 25 records in the same request|
66- | deadDetail | Get a deleted record by ID |
67- | deadList | List deleted records (paginated) |
68- | delete | Soft-delete a record by ID |
69- | detail | Get an active record by ID |
70- | edit | Update specific fields |
71- | list | List active records (paginated) |
72- | listOne | List one record based on params |
73- | selectRaw | Execute a predefined raw SQL query safely |
74-
75- ``` ts
76- import { GritRequester } from ' grit-requester-js' ;
77-
78- interface IUser {
79- id: string ;
80- name: string ;
81- email: string ;
82- }
83-
84- // configure grit requester
85- const ms = new GritRequester ({
86- baseUrl: ' http://localhost:8001' ,
87- token: process .env .SERVICE_TOKEN || ' ' ,
88- secret: process .env .SERVICE_SECRET || ' ' ,
89- context: process .env .SERVICE_CONTEXT || ' ' ,
90- });
91-
92- // make a request from domain
93- const resultFile = await ms .domain <IUser >(' user' ).add ({
94- name: ' example' ,
95- email: ' example@example.com'
96- });
53+ | Path | Description |
54+ | ----------------- | -------------------------------------------|
55+ | add | Create a new record |
56+ | bulk | Fetch specific records by IDs |
57+ | bulk_add | Create up to 25 records in the same request|
58+ | dead_detail | Get a deleted record by ID |
59+ | dead_list | List deleted records (paginated) |
60+ | delete | Soft-delete a record by ID |
61+ | detail | Get an active record by ID |
62+ | edit | Update specific fields |
63+ | list | List active records (paginated) |
64+ | list_one | List one record based on params |
65+ | select_raw | Execute a predefined raw SQL query safely |
66+
67+ ``` python
68+ from grit_requester import GritService, GritConfig
69+
70+ # configure grit requester
71+ config = GritConfig(
72+ base_url = os.getenv(" SERVICE_BASE_URL" ),
73+ auth_url = os.getenv(" SERVICE_AUTH_URL" ),
74+ token = os.getenv(" SERVICE_TOKEN" ),
75+ secret = os.getenv(" SERVICE_SECRET" ),
76+ context = os.getenv(" SERVICE_CONTEXT" ),
77+ )
78+
79+ ms = GritService(config)
80+
81+ # make a request from domain
82+ users = ms.domain(" user" ).list_all(
83+ filters = [{ " field" : " name" , " type" : " eql" , " value" : " Admin" }]
84+ )
85+
86+ # you can save the domain context to reuse
87+ user_ms = ms.domain(" user" )
88+
89+ user = user_ms.detail(users[0 ][" id" ])
9790
9891```
9992---
10093
101- ## 🧪 Testing
102-
103- Run tests:
104-
105- ``` bash
106- npm run test
107- ```
108-
109- Run test coverage
110- ``` bash
111- npm run coverage:
112- ```
113-
114- Visualize unit coverage:
115-
116- ``` bash
117- open ./coverage/unit/lcov-report/index.html
118- ```
119-
120- Visualize feature coverage:
121-
122- ``` bash
123- open ./coverage/feature/lcov-report/index.html
124- ```
125-
12694## 🔧 License
12795
12896MIT © [ Not Empty] ( https://github.com/not-empty )
0 commit comments