Browse Source

pass payload unchanged to underlying client

tags/v1.0.0
ojizero 1 year ago
parent
commit
602695d042
No account linked to committer's email address
5 changed files with 14 additions and 25 deletions
  1. 1
    1
      README.md
  2. 10
    21
      examples/sample-elasticsearch-client/index.js
  3. 1
    1
      package-lock.json
  4. 1
    1
      package.json
  5. 1
    1
      src/client.ts

+ 1
- 1
README.md View File

@@ -346,7 +346,7 @@ This is still a work in progress :D any help is appreciated
- [x] Finish documentations
- [x] Why?
- [x] More on external API
- [ ] Support non JSON payload
- [x] Support non JSON payload
- [x] Get `onError: resolve` to work
- [x] Support simplified form for validation
- [x] Finalize behvaiour of genreator method functions

+ 10
- 21
examples/sample-elasticsearch-client/index.js View File

@@ -14,6 +14,10 @@ function makeESClient (host) {
path: '/:indexName',
method: 'PUT',
}),
deleteIndex: client.route({
path: '/:indexName',
method: 'DELETE',
}),
getDocument: client.route({
path: '/:indexName/:docType/:docId',
method: 'GET',
@@ -22,29 +26,10 @@ function makeESClient (host) {
path: '/:indexName/:docType/:docId',
method: 'POST',
}),
// TODO: elastic's bulk API currently is incompatible with portal :D
bulkOperation: client.route({
path: '/_bulk',
method: 'POST',
// You can pass any Joi based schema for validation
// Or you can use the simplified syntax provided by portal
// Or you can use any custom object withe a `validate` method
// body: Joi.string().required(),
// Joi.object({
// body: Joi.array().items(
// Joi.object({
// index: Joi.object({
// _index: Joi.string().required(),
// _type: Joi.string().required(),
// _id: Joi.string(),
// }).required(),
// }),
// Joi.object(),
// ).required()
// }).required(),
// headers: {
// 'Content-Type': 'application/text',
// }
contentType: 'application/x-ndjson',
}),
}
}
@@ -68,7 +53,11 @@ if (require.main === module) {
delete response._rawResponse // This is a HUGE object
console.log({ getDocument: { stringifiedResponse: JSON.stringify(response) } })

response = await client.bulkOperation()
response = await client.bulkOperation({
payload: `{"index":{"_index":"test-index","_type":"test-type","_id":"bulk-document-id"}}
{"a":{"test":"bulkoperation"}}
`
})
delete response._rawResponse // This is a HUGE object
console.log({ getDocument: { stringifiedResponse: JSON.stringify(response) } })
})()

+ 1
- 1
package-lock.json View File

@@ -1,6 +1,6 @@
{
"name": "@ojizero/portal",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
{
"name": "@ojizero/portal",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.6",
"description": "HTTP API clients ... simplified.",
"main": "lib/index.js",
"publishConfig": {

+ 1
- 1
src/client.ts View File

@@ -168,7 +168,7 @@ export class PortalClient implements Client {
timeout: timeout * 1000,
throwHttpErrors: onHttpErrors !== 'resolve',
// TODO: what if the payload is undefined ?
body: isJson ? payload : JSON.stringify(payload),
body: payload,
}
}


Loading…
Cancel
Save