The RESTCONF protocol uses HTTP methods to identify the CRUD operations requested for a particular resource. The POST RESTCONF method represents "create" NETCONF operation. The POST method is sent by the client to create a data resource or invoke an operation resource. The server uses the target resource type to determine how to process the request.


Both the POST and PUT methods can be used to create data resources. The difference is that for POST, the client does not provide the resource identifier for the resource that will be created. The target resource for the POST method for resource creation is the parent of the new resource. The target resource for the PUT method for resource creation is the new resource.


Resource Types That Support POST
Type
Description
Datastore
Create a top-level configuration data resource
Data
Create a configuration data child resource
Operation
Invoke an RPC operation


Create Resource Mode


If the target resource type is a datastore or data resource, then the POST is treated as a request to create a top-level resource or child resource, respectively.  The message-body is expected to contain the content of a child resource to create within the parent (target resource). The data model for the child tree is the subtree, as defined by YANG for the child resource.


The message-body MUST contain exactly one instance of the expected data resource.
The parent of the node that is being created MUST exist.



The "insert" and "point" query parameters are supported by the POST method for datastore and data resources. These parameters are only allowed if the list or leaf-list is "ordered-by user". If the POST method succeeds, a "201 Created" status-line is returned and there is no response message-body.  A "Location" header field identifying the child resource that was created is present in the response in this case.

If the data resource already exists, then the POST request will fail and a "409 Conflict" status-line will be returned. If the user is not authorized to create the target resource, an error response containing a "403 Forbidden" status-line will be returned.


Example:


To create a new "jukebox" resource, the client might send the following:

      POST /restconf/data HTTP/1.1
      Host: example.com
      Content-Type: application/yang-data+json

      { "example-jukebox:jukebox" : {} }


If the resource is created, the server might respond as follows:

      HTTP/1.1 201 Created
      Date: Thu, 26 Jan 2017 20:56:30 GMT
      Server: example-server
      Location: https://example.com/restconf/data/\
          example-jukebox:jukebox
      Last-Modified: Thu, 26 Jan 2017 20:56:30 GMT
      ETag: "b3a3e673be2"



To create a new list "artist" resource within the "library" resource, the client might send the following request:


      POST /restconf/data/example-jukebox:jukebox/library HTTP/1.1
      Host: example.com
      Content-Type: application/yang-data+json

      {
        "example-jukebox:artist" : [
          {
            "name" : "Foo Fighters"
          }
        ]
      }


If the resource is created, the server might respond as follows:


      HTTP/1.1 201 Created
      Date: Thu, 26 Jan 2017 20:56:30 GMT
      Server: example-server
      Location: https://example.com/restconf/data/\
          example-jukebox:jukebox/library/artist=Foo%20Fighters
      Last-Modified: Thu, 26 Jan 2017 20:56:30 GMT
      ETag: "b3830f23a4c"


To create a new list "album" resource for this artist within the "jukebox" resource, the client might send the following request:


      POST /restconf/data/example-jukebox:jukebox/\
          library/artist=Foo%20Fighters HTTP/1.1
      Host: example.com
      Content-Type: application/yang-data+xml

      <album xmlns="http://example.com/ns/example-jukebox">
        <name>Wasting Light</name>
        <year>2011</year>
      </album>


If the resource is created, the server might respond as follows:


      HTTP/1.1 201 Created
      Date: Thu, 26 Jan 2017 20:56:30 GMT
      Server: example-server
      Location: https://example.com/restconf/data/\
          example-jukebox:jukebox/library/artist=Foo%20Fighters/\
          album=Wasting%20Light
      Last-Modified: Thu, 26 Jan 2017 20:56:30 GMT
      ETag: "b8389233a4c"




Invoke Operation Mode


If the target resource type is an operation resource, then the POST method is treated as a request to invoke that operation. The message-body (if any) is processed as the operation input parameters. If the POST request succeeds, a "200 OK" status-line is returned if there is a response message-body, and a "204 No Content" status-lineis returned if there is no response message-body. If the user is not authorized to invoke the target operation, an error response containing a "403 Forbidden" status-line will be returned. 


Example:

In this example, the client is invoking the "get-config" operation.
A client might send a "get-config" request as follows:


POST /restconf/operations/get-config HTTP/1.1
Host: example.com
Content-Type: application/yang-data+json

{
    "input" : {
        "source" : {
            "candidate": [null]
        },
        "ietf-netconf-with-defaults:with-defaults" : "trim"
    }
}


A client might send a "edit-config" request as follows:


POST /restconf/operations/edit-config HTTP/1.1
Host: example.com
Content-Type: application/yang-data+json

 <edit-config>
    <target>
      <candidate/>
    </target>
    <default-operation>merge</default-operation>
    <test-option>set</test-option>
    <config>
      <jukebox  xmlns="http://example.com/ns/example-jukebox">
          <library>
             <artist>
                <name>Foo Fighters</name>

             </artist>
          </library>
      </jukebox>
    </config>
  </edit-config>


For more details refer to RESTCONF [RFC8040]