Skip to content

Document how to extend request handler context#53271

Merged
mshustov merged 6 commits intoelastic:masterfrom
mshustov:issue-47689-document-context-extension
Dec 19, 2019
Merged

Document how to extend request handler context#53271
mshustov merged 6 commits intoelastic:masterfrom
mshustov:issue-47689-document-context-extension

Conversation

@mshustov
Copy link
Copy Markdown
Contributor

Summary

Closes #47689
Document what is provided via request handler context & how to extend it with custom API.

@mshustov mshustov added chore Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Dec 17, 2019
@mshustov mshustov requested a review from a team as a code owner December 17, 2019 10:41
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@mshustov
Copy link
Copy Markdown
Contributor Author

retest

@mshustov
Copy link
Copy Markdown
Contributor Author

retest

Comment on lines +3 to +5
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [Logger](./kibana-plugin-server.logger.md) > [get](./kibana-plugin-server.logger.get.md)

## Logger.get() method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about this one

Comment on lines +1472 to +1481
core.http.registerRouteHandlerContext('myPlugin', (context, req, res) => {
return { client: client.asScoped(req) };
});

router.get(
{ path: '/api/my-plugin/', validate },
async (context, req, res) => {
const data = await context.myPlugin.client.callAsCurrentUser('endpoint');
...
}
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

Does that works without casting context to any though ?

export type RequestHandler<
  P extends ObjectType,
  Q extends ObjectType,
  B extends ObjectType | Type<Buffer> | Type<Stream>,
  Method extends RouteMethod = any
> = (
  context: RequestHandlerContext,
  request: KibanaRequest<TypeOf<P>, TypeOf<Q>, TypeOf<B>, Method>,
  response: KibanaResponseFactory
) => IKibanaResponse<any> | Promise<IKibanaResponse<any>>;
export interface RequestHandlerContext {
  core: {
    savedObjects: {
      client: SavedObjectsClientContract;
    };
    elasticsearch: {
      dataClient: IScopedClusterClient;
      adminClient: IScopedClusterClient;
    };
    uiSettings: {
      client: IUiSettingsClient;
    };
  };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I did not see the declare module 'src/core/server' statement

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mshustov mshustov merged commit ecf8657 into elastic:master Dec 19, 2019
@mshustov mshustov deleted the issue-47689-document-context-extension branch December 19, 2019 09:12
mbondyra added a commit to mbondyra/kibana that referenced this pull request Dec 19, 2019
…f github.com:mbondyra/kibana into IS-51910_share-lens-change-index-pattern-in-discover

* 'IS-51910_share-lens-change-index-pattern-in-discover' of github.com:mbondyra/kibana:
  [Discover] Remove angular field filter template code (elastic#53513)
  [APM] Improve table and other panel loading states (elastic#53459)
  Security/Spaces - cleanup react warnings (elastic#53287)
  Revert "NP licensing add functional tests (elastic#53002)" (elastic#53577)
  NP licensing add functional tests (elastic#53002)
  fix onLicenseInfoChange callback to be called on update (elastic#53559)
  Document how to extend request handler context (elastic#53271)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported chore Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v7.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document how to extend context with elasticsearch.createCluster result

3 participants