0

Background

I'm designing a command-line API to a HPC Cluster (it API might eventually be published over the web as well).

The question

I wonder what would be the be the recommended strategy for emulating REST "end-points" on the command-line.

I can see two options:

  1. Use a separate command/scriptfile/binary, for each endpoint, with command line flags only for filtering and selecting output format (when other than default). An endpoint for "projects", would then be a separate command, in some folder, so that you would execute it with myrestfulcliapi/projects [optional other flags]
  2. Use a single command/script-file/binary, and select endpoint with a command-line flag, so that one endpoint might be executed with myrestfulcliapi --endpoint=projects [optional other flags]

If there are no established best practices for this, what pros and cons do you see with the respective options (technically, conceptually, or in any other aspect), and which one would you recommend?

Samuel Lampa
  • 4,336
  • 5
  • 42
  • 63

1 Answers1

0

Ok, so after a few cups of coffee and still no answers here, I finally figured out my favorite solution:

Use a combination of the two: Create separate scripts for each endpoint, consisting of a simple shell script, that in turn calls another file (python, Go binary or something), where the endpoint is added as a flag.

So, I'll have a bash script (since I'm in linux), named "projects", which contains:

#!/bin/bash
python api.py --endpoint="projects" "$@"

(... where the "$@" part just forwards the command line flags to the python script)

Samuel Lampa
  • 4,336
  • 5
  • 42
  • 63