@swell/cli
Version:
Swell's command line interface/utility
35 lines (34 loc) • 1.24 kB
JavaScript
import { Args, Flags } from '@oclif/core';
import { HttpMethod } from '../../lib/api.js';
import { SwellApiCommand } from '../../swell-api-command.js';
export default class ApiPost extends SwellApiCommand {
static summary = 'Send a POST request to the Swell API.';
static description = `Create new resources in the Swell Backend API.
You can provide a JSON body directly or specify a file path containing JSON data.`;
static args = {
path: Args.string({
description: 'API endpoint path (must start with /)',
required: true,
}),
};
static flags = {
body: Flags.string({
description: 'Request body (inline JSON or file path)',
}),
live: Flags.boolean({
description: 'Use live environment instead of test',
default: false,
}),
};
static examples = [
'swell api post /products --body \'{"name": "Product", "price": 100}\'',
'swell api post /products --body ./product.json',
'swell api post /functions/my-app/create-order --body \'{"items":["sku-1"]}\'',
];
get method() {
return HttpMethod.POST;
}
async run() {
await this.request(ApiPost);
}
}