github.com/rpdict/ponzu@v0.10.1-0.20190226054626-477f29d6bf5e/docs/src/Interfaces/API.md (about)

     1  title: API Package Interfaces
     2  
     3  Ponzu provides a set of interfaces from the `system/api` package which enable 
     4  richer interaction with your system from external clients. If you need to allow 
     5  3rd-party apps to manage content, use the following interfaces.
     6  
     7  The API interfaces adhere to a common function signature, expecting an 
     8  `http.ResponseWriter` and `*http.Request` as arguments and returning an `error`.
     9  This provides Ponzu developers with full control over the request/response 
    10  life-cycle.
    11  
    12  ---
    13  
    14  ## Interfaces
    15  
    16  ### [api.Createable](https://godoc.org/github.com/rpdict/ponzu/system/api#Createable)
    17  Externalable enables 3rd-party clients (outside the CMS) to send content via a 
    18  `multipart/form-data` encoded `POST` request to a specific endpoint: 
    19  `/api/content/create?type=<Type>`. When `api.Createable` is implemented, content 
    20  will be saved from the request in a "Pending" section which will is visible only 
    21  within the CMS.
    22  
    23  To work with "Pending" data, implement the [`editor.Mergeable`](/Interfaces/Editor#editormergeable)
    24  interface, which will add "Approve" and "Reject" buttons to your Content types'
    25  editor -- or implement [`api.Trustable`](#apitrustable) to bypass 
    26  the "Pending" section altogether and become "Public" immediately. 
    27  
    28  ##### Method Set
    29  
    30  ```go 
    31  type Createable interface {
    32      Create(http.ResponseWriter, *http.Request) error
    33  }
    34  ```
    35  
    36  ##### Implementation
    37  ```go
    38  func (p *Post) Create(res http.ResponseWriter, req *http.Request) error {
    39      return nil
    40  }
    41  ```
    42  
    43  ---
    44  
    45  ### [api.Updateable](https://godoc.org/github.com/rpdict/ponzu/system/api#Updateable)
    46  Updateable enables 3rd-party clients (outside the CMS) to update existing content 
    47  via a `multipart/form-data` encoded `POST` request to a specific endpoint: 
    48  `/api/content/update?type=<Type>&id=<id>`. Request validation should be employed 
    49  otherwise any client could change data in your database.
    50  
    51  ##### Method Set
    52  
    53  ```go 
    54  type Updateable interface {
    55      Update(http.ResponseWriter, *http.Request) error
    56  }
    57  ```
    58  
    59  ##### Implementation
    60  ```go
    61  func (p *Post) Update(res http.ResponseWriter, req *http.Request) error {
    62      return nil
    63  }
    64  ```
    65  
    66  ---
    67  
    68  ### [api.Deleteable](https://godoc.org/github.com/rpdict/ponzu/system/api#Deleteable)
    69  Updateable enables 3rd-party clients (outside the CMS) to delete existing content 
    70  via a `multipart/form-data` encoded `POST` request to a specific endpoint: 
    71  `/api/content/delete?type=<Type>&id=<id>`. Request validation should be employed 
    72  otherwise any client could delete data from your database.
    73  
    74  ##### Method Set
    75  
    76  ```go 
    77  type Deleteable interface {
    78      Delete(http.ResponseWriter, *http.Request) error
    79  }
    80  ```
    81  
    82  ##### Implementation
    83  ```go
    84  func (p *Post) Delete(res http.ResponseWriter, req *http.Request) error {
    85      return nil
    86  }
    87  ```
    88  
    89  ---
    90  
    91  ### [api.Trustable](https://godoc.org/github.com/rpdict/ponzu/system/api#Trustable)
    92  Trustable provides a way for submitted content (via `api.Createable`) to bypass 
    93  the `editor.Mergeable` step in which CMS end-users must manually click the 
    94  "Approve" button in order for content to be put in the "Public" section and access 
    95  via the content API endpoints. `api.Trustable` has a single method: `AutoApprove` 
    96  which will automatically approve content, bypassing the "Pending" section 
    97  altogether.
    98  
    99  ```go
   100  type Trustable interface {
   101      AutoApprove(http.ResponseWriter, *http.Request) error
   102  }
   103  ```
   104  
   105  ##### Implementation
   106  ```go
   107  func (p *Post) AutoApprove(res http.ResponseWriter, req *http.Request) error {
   108      return nil
   109  }
   110  ```