File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -563,9 +563,34 @@ must also contain a [Collection](./Collection.md).
563
563
564
564
Prepends this to the compiled [ path] ( #path )
565
565
566
+ #### Inheritance defaults
567
+
568
+ ``` typescript
569
+ export class MyEndpoint <
570
+ O extends RestGenerics = any ,
571
+ > extends RestEndpoint <O > {
572
+ // this allows us to override the prefix in production environments, with a dev fallback
573
+ urlPrefix = process .env .API_SERVER ?? ' http://localhost:8000' ;
574
+ }
575
+ ```
576
+
577
+ [ Learn more about inheritance patterns] ( #inheritance ) for RestEndpoint
578
+
579
+ #### Instance overrides
580
+
581
+ ``` typescript
582
+ export const getTicker = new RestEndpoint ({
583
+ urlPrefix: ' https://api.exchange.coinbase.com' ,
584
+ path: ' /products/:product_id/ticker' ,
585
+ schema: Ticker ,
586
+ });
587
+ ```
588
+
589
+ #### Dynamic prefix
590
+
566
591
::: tip
567
592
568
- For a dynamic prefix, try overriding the url() method:
593
+ For a dynamic prefix, try overriding the url() method instead :
569
594
570
595
``` ts
571
596
const getTodo = new RestEndpoint ({
Original file line number Diff line number Diff line change @@ -657,8 +657,9 @@ export const IssueResource= resource({
657
657
658
658
## Function Inheritance Patterns
659
659
660
- To reuse code around ` Resource ` design, you can create your own function that calls resource().
661
- This has similar effects as class-based inheritance.
660
+ To reuse code related to ` Resource ` definitions, you can create your own function that calls resource().
661
+ This has similar effects as class-based inheritance, with the added benefit of allowing for complete
662
+ typing overrides.
662
663
663
664
` ` ` typescript
664
665
import {
@@ -673,6 +674,8 @@ import {
673
674
export class AuthdEndpoint <
674
675
O extends RestGenerics = any ,
675
676
> extends RestEndpoint <O > {
677
+ urlPrefix = process .env .API_SERVER ?? ' http://localhost:8000' ;
678
+
676
679
async getRequestInit(body : any ): Promise <RequestInit > {
677
680
return {
678
681
... (await super .getRequestInit (body )),
@@ -681,7 +684,7 @@ export class AuthdEndpoint<
681
684
}
682
685
}
683
686
684
- export function createMyResource <O extends ResourceGenerics = any >({
687
+ export function myResource <O extends ResourceGenerics = any >({
685
688
schema ,
686
689
Endpoint = AuthdEndpoint ,
687
690
... extraOptions
You can’t perform that action at this time.
0 commit comments