Skip to content

Commit

Permalink
docs(usage-guide): add alternative way to use classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilqa committed Jan 25, 2025
1 parent d7e9cf9 commit f7c348c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions website/docs/usage-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,29 @@ export default {

Specify functions for each method within the class. The main requirement is that it should be the default export.

```js
export default class Resource {
```ts
export default class SomeResource {
get(req, res, routeParams) {
const { documentId, draftId } = routeParams;
res.end(`Requested document ${documentId} and his draft ${draftId}`);
}

post(req, res, routeParams) {
const { documentId, draftId } = routeParams;
res.end(`Created draft ${draftId} for document ${documentId}`);
patch(req, res, routeParams) {
// ...
}
}
```

patch(req, res, routeParams) {
Alternatively, you can export a class instance:

```ts
class SomeResource {
get(req, res, routeParams) {
// ...
}
}

export default new SomeResource();
```

### Methods in Filenames
Expand Down

0 comments on commit f7c348c

Please sign in to comment.