github.com/bosssauce/ponzu@v0.11.1-0.20200102001432-9bc41b703131/examples/updateable/README.md (about)

     1  # Updateable
     2  
     3  This example shows how to enable outside clients to update content to your CMS.
     4  All content submitted must be done through a POST request encoded as `multipart/form-data`
     5  to the API endpoint `/api/content/update?type=<Type>&id=<id>`
     6  
     7  ## Song example
     8  Imagine an app that lets users add Spotify music to a global playlist, and you need them
     9  to supply songs in the format:
    10  ```go
    11  type Song struct {
    12  	item.Item
    13  
    14  	Title      string `json:"title"`
    15  	Artist     string `json:"artist"`
    16  	Rating     int    `json:"rating"`
    17  	Opinion    string `json:"opinion"`
    18  	SpotifyURL string `json:"spotify_url"`
    19  }
    20  ```
    21  
    22  See the file `content/song.go` and read the comments to understand the various
    23  methods needed to satisfy required interfaces for this kind of activity.
    24  
    25  ### Overview
    26  1. Implement `api.Updateable` with the `Update(http.ResponseWriter, *http.Request) error` method to allow outside POST requests. 
    27  2. Consistent with the createable example, authentication can be validated in `BeforeAPIUpdate(http.ResponseWriter, *http.Request) error`
    28  
    29  There are various validation and request checks shown in this example as well. 
    30  Please feel free to modify and submit a PR for updates or bug fixes!
    31