Skip to content

Custom Service Routes beyond CRUD (without using X-Service-Method) #3423

Answered by daffl
dustinc asked this question in Q&A
Discussion options

You must be logged in to vote

You can create any route structure you need with placeholders and custom services. In this case e.g.

class GigConfirmService {
  constructor(app) {
    this.app = app
  }

  async create (data, params) {
    const gigId = params.route.id
    return this.app.service('gigs').patch(gigId, { status: 'confirmed' }) 
  }
}

class GigRequestService {
  constructor(app) {
    this.app = app
  }

  async find (params) {
    const gigId = params.route.id
    return this.app.service('gigs').find({
      query: { gigId }
    })
  }
}

app.use('gigs/:id/confirm', new GigConfirmService(app))
app.use('gigs/:id/requests', new GigRequestService(app))

How service methods map to HTTP methods is documented i…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@dustinc
Comment options

@daffl
Comment options

daffl Feb 3, 2024
Maintainer

Answer selected by dustinc
Comment options

You must be logged in to vote
2 replies
@Mairu
Comment options

@dustinc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3422 on February 02, 2024 23:03.