To send simple GET request the following command can be used:
> curl http://restconf-dev/restconf/data/restconf-state/capabilities \ -H "Accept:application/yang-data+xml" <?xml version="1.0" encoding="UTF-8"?> <capabilities xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf-monitoring"> <capability>urn:ietf:params:restconf:capability:depth:1.0</capability> <capability>urn:ietf:params:restconf:capability:with-defaults:1.0</capability> <capability>urn:ietf:params:restconf:capability:defaults:1.0?basic-mode=explicit</capability> <capability>urn:ietf:params:restconf:capability:fields:1.0</capability> <capability>urn:ietf:params:restconf:capability:replay:1.0</capability> <capability>urn:ietf:params:restconf:capability:filter:1.0</capability> <capability>urn:ietf:params:restconf:capability:yang-patch:1.0</capability> </capabilities>
In order to retrieve data in different encoding use --header (-H) parameter with specific Accept header value (XML or JSON).
The following request "Accepts" replies in JSON encoding:
> curl http://restconf-dev/restconf/data/restconf-state/capabilities \ -H "Accept:application/yang-data+json" { "capabilities": { "capability": [ "urn:ietf:params:restconf:capability:depth:1.0", "urn:ietf:params:restconf:capability:with-defaults:1.0", "urn:ietf:params:restconf:capability:defaults:1.0?basic-mode=explicit", "urn:ietf:params:restconf:capability:fields:1.0", "urn:ietf:params:restconf:capability:replay:1.0", "urn:ietf:params:restconf:capability:filter:1.0", "urn:ietf:params:restconf:capability:yang-patch:1.0" ] } }
The same request with RESTCONF query parameters, for example, "depth" would look as follows:
> curl http://restconf-dev/restconf/data/restconf-state/capabilities?depth=1 <?xml version="1.0" encoding="UTF-8"?> <capabilities xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf-monitoring"/>
To send EDIT request to create a new value "uint32.1" of type "uint32" and set to value 16:
> curl -i \ -H "Accept: application/yang-data+json" \ -H "Content-Type: application/json" \ -X POST -d '{"uint16.1":16}' \ http://restconf-dev/restconf/data HTTP/1.1 201 Created Date: Thu, 21 Apr 2016 21:22:23 GMT Server: Apache/2.4.7 (Ubuntu) Cache-Control: no-cache Pragma: no-cache Location: http://restconf-dev/restconf/data/uint16.1 Last-Modified: Thu, 21 Apr 2016 21:22:24 GMT ETag: 57472 Content-Length: 0
To Receive RESTCONF Notifications subscribe to event stream by GET request:
> curl http://restconf-dev/restconf/stream -H "Accept:text/event-stream" data: data: <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"> data: <eventTime>2016-04-21T21:04:51Z</eventTime> data: <netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"> data: <changed-by> data: <username>yumaworks</username> data: <session-id>4</session-id> data: <source-host>127.0.0.1</source-host> data: </changed-by> data: <datastore>running</datastore> data: <edit> data: <target data: xmlns:t="http://netconfcentral.org/ns/test">/t:uint32.1</target> data: <operation>create</operation> data: </edit> data: </netconf-config-change> data: </notification>
To send GET Request using TLS transport:
> curl --cert /ssl/client.crt:password \ --key /ssl/clients.key \ --cacert /ssl/ca.crt \ https://restconf-dev/restconf/yang-library-version { "yang-library-version":"2016-06-21" }
To CREATE a new entry using PUT method and an input file use the following request:
> curl -vX PUT -d @$HOME/input.json \ --header "Content-Type: application/yang-data+json" \ http://localhost/restconf/data/ietf-interfaces:interfaces/interface=test2
Where, input.json:
{ "interface": [ { "name": "test1", "type": "iana-if-type:l2vlan" } ] }
To CREATE a new entry using PATCH method and an input file use the following request:
> curl -vX patch -d @$HOME/mode.json \ --header "Content-Type: application/yang-data+json" \ http://localhost/restconf/data/ietf-interfaces:interfaces
Where, input.json:
{ "interfaces" : { "interface": [ { "name": "test1", "type": "iana-if-type:other" } ] } }