in opensearch-notebooks/src/main/kotlin/org/opensearch/notebooks/resthandler/NotebookRestHandler.kt [95:122]
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
return when (request.method()) {
POST -> RestChannelConsumer {
client.execute(CreateNotebookAction.ACTION_TYPE,
CreateNotebookRequest(request.contentParserNextToken()),
RestResponseToXContentListener(it))
}
PUT -> RestChannelConsumer {
client.execute(
UpdateNotebookAction.ACTION_TYPE,
UpdateNotebookRequest(request.contentParserNextToken(), request.param(NOTEBOOK_ID_FIELD)),
RestResponseToXContentListener(it))
}
GET -> RestChannelConsumer {
client.execute(GetNotebookAction.ACTION_TYPE,
GetNotebookRequest(request.param(NOTEBOOK_ID_FIELD)),
RestResponseToXContentListener(it))
}
DELETE -> RestChannelConsumer {
client.execute(DeleteNotebookAction.ACTION_TYPE,
DeleteNotebookRequest(request.param(NOTEBOOK_ID_FIELD)),
RestResponseToXContentListener(it))
}
else -> RestChannelConsumer {
it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed"))
}
}
}