Skip to main content

Create an API endpoint

Marblism already generates all the basic API endpoints you would need for each entity in your database:

  • findMany
  • findOne
  • save
  • update
  • delete

Let's see how to add an endpoint that returns the number of likes a tweet has.

1. Define the route in the controller


export class TweetController {
async countLikes(@Param('tweetId') tweetId: string, @Req() request: Request) {
const likesNumber = await this.likeDomainFacade.countByTweetId(tweetId)

return likesNumber

2. Create the query


export class LikeDomainFacade {
async countbyTweetId(tweetId: string): Promise<number> {
const numberLikes = this.repository.countBy({

return numberlikes

3. Register your newly created endpoint in the front-end


export class TweetApi {
export function countLikes(
tweetId: string,
): Promise<number> {
return HttpService.api.get(

To use it in the front-end:

const numberLikes = await Api.Tweet.countLikes(tweetId)