NASA666

不以物喜,不以己悲.

JSON API index

Users

type User struct {
	ID       int64  `json:"id"`
	Name     string `json:"name" form:"name"`
	Password string `json:"password,omitempty" form:"password" sql:"-"`
	Recovery string `json:"-"`
	Digest   []byte `json:"-"`
	Email    string `json:"email,omitempty" form:"email" binding:"required" sql:"unique"`
	Posts    []Post `json:"posts"`
}

GET /api/users

Displays all users and their data

GET /api/user/:id

Displays data of a single user.

POST /api/user

Creates a new user. Required parameters are email and password.

{
	"name": "Juuso",
	"password": "foo",
	"email": "foo@example.com"
}

POST /api/user/login

Logins a user and if successful, returns session cookie. Required parameters are email and password.

{
	"email": "foo@example.com",
	"password": "foo",
}

GET /api/user/logout

Logs out and deletes the current session.


Posts

type Post struct {
	ID        int64  `json:"id"`
	Title     string `json:"title" form:"title" binding:"required"`
	Content   string `json:"content" form:"content" sql:"type:text"`
	Markdown  string `json:"markdown" form:"markdown" sql:"type:text"`
	Date      int64  `json:"date"`
	Slug      string `json:"slug"`
	Author    int64  `json:"author"`
	Excerpt   string `json:"excerpt"`
	Viewcount uint   `json:"viewcount"`
	Published bool   `json:"-"`
}

GET /api/posts

Displays all posts

GET /api/post/:slug

Displays a single post

POST /api/post

Creates a new post. Requires active session. Example payload:

{
	"title": "My first post",
	"content": "This is my first post!"
}

GET /api/post/:slug/publish

Publishes a post. Requires active session. Requires post slug as parameter.

POST /api/post/:slug/edit

Updates a post. Requires active session. Required parameters are slug, content and title.

{
	"slug": "my-first-post",
	"title": "My first post edited",
	"content": "This is my first post, edited."
}

GET /api/post/:slug/delete

Deletes a post. Requires active session. Requires post slug as parameter.


Search

type Search struct {
	Query string `json:"query" form:"query" binding:"required"`
	Score float64
	Posts []Post
}

POST /api/posts/search

Uses site's search to find posts with given query. Example payload:

{
	"query": "first"
}

Settings

type Vertigo struct {
	Name               string  `json:"name" form:"name" binding:"required"`
	Hostname           string  `json:"hostname" form:"hostname" binding:"required"`
	URL                url.URL `json:"-,omitempty"`
	Firstrun           bool    `json:"firstrun,omitempty"`
	CookieHash         string  `json:"cookiehash,omitempty"`
	AllowRegistrations bool    `json:"allowregistrations" form:"allowregistrations"`
	Description        string  `json:"description" form:"description" binding:"required"`
	Mailer             SMTP    `json:"smtp"`
}

GET /api/settings

Displays settings given in installation wizard. Requires active session cookie.

POST /api/settings

Updates the settings with given data. Requires active session cookie.

{
	"hostname": "example.com",
	"name": "Foo Blog",
	"description": "Foo's test blog",
	"mailgun": {
		"mgdomain": "foo",
		"mgprikey": "foo"
	}
}