Optimize Request: farrow-api-client codegen
Closed this issue · 3 comments
tqma113 commented
For now, the generated code is like this:
import { apiPipeline } from 'farrow-api-client'
... // type declaration
export const url = '/api'
export const api = {
/**
* @remarks get note content
*/
getNote: (input: GetNoteInput) =>
apiPipeline.invoke(url, { path: ['getNote'], input }) as Promise<
GetNoteSuccess | NoteNotExist | NoteIsBroken | SystemError
>,
... // anthor apis
}
in this segment, the url
is constant but need pass to api.invoke
everytime. IMO, I prefer:
import { createApiPipeline } from 'farrow-api-client'
... // type declaration
export const url = '/api'
export const apiPipeline = createApiPipeline(url)
export const api = {
/**
* @remarks get note content
*/
getNote: (input: GetNoteInput) =>
apiPipeline.invoke({ path: ['getNote'], input }) as Promise<
GetNoteSuccess | NoteNotExist | NoteIsBroken | SystemError
>,
... // anthor apis
}
reason:
- generated code splited to file by
services
services
defined infarrow.config.js
andurl
is independent in eachservice
- one
url
-> oneservice
-> onefile
generated -> oneapi
created bycreateApiPipeline
Lucifier129 commented
It looks good!
I will refactor farrow-api-* as you suggest.
Lucifier129 commented
farrow v1.8.5
was released with this feature. Now each api
has its own apiPipeline
, and all api
share one root apiPipeline.
Lucifier129 commented