Skip to content

Commit

Permalink
feat(rest): new Herbs2REST interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dalssoft committed Aug 14, 2023
1 parent 608ec24 commit da24813
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/templates/infra/api/rest/index.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const express = require('express')
const { populateMetadata, generateEndpoints } = require('@herbsjs/herbs2rest')
const { endpoints, routes } = require('@herbsjs/herbs2rest')
const { herbarium } = require('@herbsjs/herbarium')
const controller = require('./controller')

Expand All @@ -14,27 +14,29 @@ async function rest(app, config) {

async function herbs2rest({ server, config }) {

// Herbs2REST will populate the Express endpoints
// Herbs2REST will create Express endpoints
// based on your use cases and entities.

// 1. Prepare your use cases metadata if needed
// Ex:
// herbarium.usecases.get('SearchUser').metadata({
// REST: [{
// version: 'v1',
// method: 'GET',
// path: '/v1/search/',
// parameters: { query: { id: String } },
// }]
// })

// 2. Populate the metadata
// Each use case will be populated with the metadata:
// version, resource, method, path, parameters, parametersHandler, controller
populateMetadata({ herbarium, controller, version: 'v1' })

// 3. Generate the endpoints based on the metadata
generateEndpoints({ herbarium, server })
// 1. Create endpoints
endpoints({ herbarium, controller }, {
'v1': (endpoints) => {
// endpoints.ignore('FindUser')

// endpoints.for('SearchUser').use({
// method: 'GET',
// path: '/v1/search/',
// parameters: { query: { id: String } },
// })

endpoints.build()
},
// 'v2': (endpoints) => {
// endpoints.build()
// }
})

// 2. Attach the endpoints to Express
routes({ herbarium, server }).attach()

}

Expand Down

0 comments on commit da24813

Please sign in to comment.