Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create batch api #612

Open
guidiego opened this issue Sep 20, 2020 · 0 comments
Open

Create batch api #612

guidiego opened this issue Sep 20, 2020 · 0 comments
Labels
client/node Node library to consume RESTful API docs feature New fetures level/easy

Comments

@guidiego
Copy link
Contributor

Motivation

We have a batch endpoint inside pRest (https://docs.postgres.rest/batch-operations/), but we don’t have an client method the reflect it yet.

Interface Sample

const table = cli.tableConnector<TestEntity>('prest.public.test')
table.batch(data) // or table.batch<TestEntityInput>(data)
table.batch([data]) // should work too

Approach

We need to change the behavior of Api.call to be able to receive adapt new parameters. Something like:

Feel free to think in a better approach

type RequestOpts<Input> = {
  data?: Input;
  query?: string;
}

public call<T>(method: Method, path: string, opts: RequestOpts): Promise<T> {
    const axiosFn = axios[method];
    const uri = this.baseUrl + path + opts.query;
    const dataGetter = (promise) => promise.then(({ data }) => data);

    if (['put', 'post', 'patch'].indexOf(method)) {
       return dataGetter(axiosFn(uri, opts.data));
    }

    return dataGetter(axiosFn(uri));
}

After doing that, we need to add a .batch method inside TableConnector:

public batch<Input = T>(data: Input) {
  this.call<T>('post', `/batch/${this.dbPath}`)
}
@avelino avelino transferred this issue from prest/prest-node Sep 30, 2021
@avelino avelino added client/node Node library to consume RESTful API docs feature New fetures level/easy labels Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client/node Node library to consume RESTful API docs feature New fetures level/easy
Projects
None yet
Development

No branches or pull requests

2 participants