@tramvai/papi 2.73.0 → 2.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ Library mostly provides strong typings to papi handlers and most of the logic of
|
|
|
24
24
|
### createPapiMethod
|
|
25
25
|
|
|
26
26
|
Options:
|
|
27
|
+
|
|
27
28
|
- `path` - specifies the path of url that current papi should handle. Required when specifying papi in tramvai DI, and not used when specified through file api.
|
|
28
29
|
- `method` - specified HTTP-method that is acceptable by current papi. By default, it equals to "all"
|
|
29
30
|
- `handler` - see [handler](#handler)
|
|
@@ -38,6 +39,7 @@ Function that handles actual request and should return. It accepts the details o
|
|
|
38
39
|
Details of the request are passed with first parameter when handler is called. You can see available properties in typings when specifying papi method. It should provide most of the data that might be required to handle the request.
|
|
39
40
|
|
|
40
41
|
Additionally, though `this` passed data that bounded to papi method:
|
|
42
|
+
|
|
41
43
|
- `deps` - resolved deps that were specified when defining papi method. Deps are resolved with [Child DI Container](concepts/di.md#container-is-a-child), so do not use it for creating caches as it won't work.
|
|
42
44
|
- `log` - instance of [LOGGER_TOKEN](references/modules/log.md#logger_token) bounded with current papi method
|
|
43
45
|
|
|
@@ -77,7 +79,7 @@ export const papi = createPapiMethod({
|
|
|
77
79
|
return {
|
|
78
80
|
testCookie,
|
|
79
81
|
a,
|
|
80
|
-
b
|
|
82
|
+
b,
|
|
81
83
|
};
|
|
82
84
|
},
|
|
83
85
|
});
|
|
@@ -111,11 +113,11 @@ export const papi = createPapiMethod({
|
|
|
111
113
|
|
|
112
114
|
cookieManager.set({ name: 'b', value: 'abc', expires: 35 });
|
|
113
115
|
|
|
114
|
-
return
|
|
116
|
+
return 'response';
|
|
115
117
|
},
|
|
116
118
|
deps: {
|
|
117
119
|
cookieManager: COOKIE_MANAGER_TOKEN,
|
|
118
|
-
}
|
|
120
|
+
},
|
|
119
121
|
});
|
|
120
122
|
```
|
|
121
123
|
|
|
@@ -126,7 +128,7 @@ Deps are resolved with ChildContainer that means they are getting resolved on ev
|
|
|
126
128
|
For example, if you want to use some papi specific cache you should create new token and provide the cache instance with that token and with option `scope: Scope.SINGLETON`
|
|
127
129
|
|
|
128
130
|
```tsx
|
|
129
|
-
import { createToken, Scope, provide } from '@tinkoff/dippy'
|
|
131
|
+
import { createToken, Scope, provide } from '@tinkoff/dippy';
|
|
130
132
|
import { createApp } from '@tramvai/core';
|
|
131
133
|
import { createPapiMethod } from '@tramvai/papi';
|
|
132
134
|
import { Cache, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
|
|
@@ -146,8 +148,8 @@ const app = createApp({
|
|
|
146
148
|
deps: {
|
|
147
149
|
createCache: CREATE_CACHE_TOKEN,
|
|
148
150
|
},
|
|
149
|
-
})
|
|
150
|
-
]
|
|
151
|
+
}),
|
|
152
|
+
],
|
|
151
153
|
});
|
|
152
154
|
|
|
153
155
|
export const papi = createPapiMethod({
|
|
@@ -166,7 +168,7 @@ export const papi = createPapiMethod({
|
|
|
166
168
|
return result;
|
|
167
169
|
},
|
|
168
170
|
deps: {
|
|
169
|
-
cache: PAPI_CACHE_TOKEN
|
|
170
|
-
}
|
|
171
|
+
cache: PAPI_CACHE_TOKEN,
|
|
172
|
+
},
|
|
171
173
|
});
|
|
172
174
|
```
|