UCDavisLibrary / fin-cli

CLI interface for a Linked Data Platform (Like fin-server)
MIT License
0 stars 0 forks source link

The http command #5

Open qjhart opened 6 years ago

qjhart commented 6 years ago

The http command, with it's subcommands allow direct access to the standard LDP http methods. These commands are basically equivalent to the direct http requests with the following additions;

1) The current authorization token is included in the request 2) relative path specifications are allowed based on the notation of a CWD for the system. 3) Some simplified input specifications via options and additional features.

We use the lower case versions for these httpd methods.

General http options

The following options are available to every one of the http sub-commands. These are described in vorpal notation.

command('http [cmd] <path>')
.option('-H --header <header>','Add additional Headers to the request')
.option('-P --print <print>','Specify what components to print to user')

In the above example, path can be relative, and is then created in relation to the cwd.

--header

This allows any header to be added to a core command. Note this command can be included on any other fin-cli command, unless otherwise specified.

# Set the format for your output
fin>get  -H 'Accept: application/rdf+xml' . 

--print

This allows users to identify what components of the communication they would like to see. This follows the httpie convention where the value is any combination of 'hbHB' where:

The default value is the value of config.print or print=hb for the http sub-commands if not specified. Individual commands can overwrite the default value, or the config.print value, but not any value specified in by an explicit --print option. The order of display is HBhb and they are separated by an empty line.

Data Input --data-binary --data-string

.option('-@ --data-binary <binary>','Specify a data file to add as the request body')
.option('-s --data-string <string>','Specify a string for the request body')
.option('--prefix','Prefix fin defined prefixes to the body')

Only zero or one of --data-binary, --data-string may be specified.

For commands that send body requests to the server, there are three methods for specifying that data. By default /dev/stdin is read as the body value. However, the two options, --data-binary and --data-string may be specified to create the body from a file, or from a string value. The data string value, is just a convenience function.

fin put --data-string="<string>" foo
# Is equivalent to 
fin put foo <<< "<string>"

--prefix

Finally, as a convenience. The --prefix option will prefix the fin system prefixes to the body payload. This just allows for simple creation of new containers. Currently, the --prefix only works with application/x-turtle formatted objects for PUT and POST and application/x-sparql for PATCH. The mime-type will be set accordingly.

# Example of using the system prefixes
fin put --prefix foo <<<'<> a ldp:Container'

head, get, delete and options

These commands only include the general options described above.

Examples

# Set the format for your output
fin get  -H 'Accept: application/ld+json'  ./

put and post

These commands have some additional options, specifying the POST content type. Additionally the checksum parameter is included. Note that even though POST and PUT have different responses, these are identified in the --print parameters.

.option('-C --checksum <checksum>','Request that client add a checksum')
.option('-@ --data-binary <binary>','Specify a data file to add.  Can be to stdin')
.option('-s --data-string <string>','Specify a string to be used as turtle formatted triples, use defined prefixes')

Only zero or one of --data-binary, --data-string may be specified.

--checksum

If checksum is not included, then the CLI will calculate the checksum and include

--data-binary

Specify a data file for input.

--data-string

This option allows a string to be used for the input to the PUT command. It can be used as a method to add simple data to a container.

find put --data-string="<string>" 
# Is equivalent to 
fin put --data-binary=/dev/stdin <<< "<string>"

The example below creates a new ldp:DirectContainer where any additions to that container are added to the x:parts property of the new car resource

fin put --prefix=`x=http://ex.org/' \
--data-string="<> a ldp:DirectContainer; a x:Car; ldp:hasMemberRelation w:parts; ldp:membershipResource <>." /car

This is equivalent to the following:

fin put --no-prefix --data-binary=/dev/stdin /car <<EOF
@prefix x:  <http://ex.org/> .
@prefix ldp:  <http://www.w3.org/ns/ldp#> .

<>
        rdf:type                w:Car ;
        rdf:type                ldp:DirectContainer ;
        ldp:membershipResource  <> ;
        ldp:hasMemberRelation   w:parts ;
EOF

patch

Patch allows queries from files or as a string. User can specify whether or not to prefix the system queries to the system.

.option('-@ --data-binary <binary>','Specify a data file as ')
.option('-s --data-string <patch>','Specify a SPARQL query to include')
.option('--(no-)prefixes','Specify to prefix either `<binary>` or `<patch>` with system prefixes')

move and copy

Both move and copy include no new options, but they do include a second parameter

command('move or copy <path> <dest>')
[general_options]

<dest> is required, and is converted to the 'Destination:` header.