Browse Source

pass payload unchanged to underlying client

modified-method-api
ojizero 4 years ago
parent
commit
602695d042
No known key found for this signature in database
GPG Key ID: FEBB7097845B0C7E
  1. 2
      README.md
  2. 31
      examples/sample-elasticsearch-client/index.js
  3. 2
      package-lock.json
  4. 2
      package.json
  5. 2
      src/client.ts

2
README.md

@ -346,7 +346,7 @@ This is still a work in progress :D any help is appreciated @@ -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

31
examples/sample-elasticsearch-client/index.js

@ -14,6 +14,10 @@ function makeESClient (host) { @@ -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) { @@ -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) { @@ -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) } })
})()

2
package-lock.json generated

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

2
package.json

@ -1,6 +1,6 @@ @@ -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": {

2
src/client.ts

@ -168,7 +168,7 @@ export class PortalClient implements Client { @@ -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