diff --git a/hc/front/urls.py b/hc/front/urls.py index 155c8ee1..fae8a337 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -12,6 +12,7 @@ urlpatterns = [ url(r'^checks/([\w-]+)/remove/$', views.remove_check, name="hc-remove-check"), url(r'^checks/([\w-]+)/log/$', views.log, name="hc-log"), url(r'^docs/$', views.docs, name="hc-docs"), + url(r'^docs/api/$', views.docs_api, name="hc-docs-api"), url(r'^about/$', views.about, name="hc-about"), url(r'^privacy/$', views.privacy, name="hc-privacy"), url(r'^integrations/$', views.channels, name="hc-channels"), diff --git a/hc/front/views.py b/hc/front/views.py index e43dc164..552825f2 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -13,7 +13,7 @@ from django.utils.crypto import get_random_string from django.utils.six.moves.urllib.parse import urlencode from hc.accounts.models import Profile from hc.api.decorators import uuid_or_400 -from hc.api.models import Channel, Check, Ping +from hc.api.models import Channel, Check, Ping, DEFAULT_TIMEOUT, DEFAULT_GRACE from hc.front.forms import AddChannelForm, NameTagsForm, TimeoutForm @@ -91,6 +91,7 @@ def docs(request): ctx = { "page": "docs", + "section": "home", "ping_endpoint": settings.PING_ENDPOINT, "check": check, "ping_url": check.url() @@ -99,6 +100,19 @@ def docs(request): return render(request, "front/docs.html", ctx) +def docs_api(request): + ctx = { + "page": "docs", + "section": "api", + "SITE_ROOT": settings.SITE_ROOT, + "PING_ENDPOINT": settings.PING_ENDPOINT, + "default_timeout": int(DEFAULT_TIMEOUT.total_seconds()), + "default_grace": int(DEFAULT_GRACE.total_seconds()) + } + + return render(request, "front/docs_api.html", ctx) + + def about(request): return render(request, "front/about.html", {"page": "about"}) diff --git a/static/css/docs.css b/static/css/docs.css index 42f16619..b5fb823d 100644 --- a/static/css/docs.css +++ b/static/css/docs.css @@ -1,4 +1,44 @@ +.docs-nav { + margin: 20px 0 0 0; + padding: 0; + list-style: none; +} + +.docs-nav li a { + display: block; + padding-bottom: 10px; +} + +.docs-nav li.active > a { + font-weight: bold; +} + + +.docs-nav ul { + margin: 0 0 0 20px; + padding: 0; + list-style: none; + +} + .curl-opts th { white-space: nowrap; font-family: monospace; +} + +h2.rule { + border-top: 1px solid #ddd; + padding-top: 20px; +} + +h3.api-section { + font-size: 14px; + font-weight: bold; + margin: 20px 0; +} + +.api-path { + font-family: monospace; + font-weight: bold; + margin-bottom: 1em; } \ No newline at end of file diff --git a/templates/front/base_docs.html b/templates/front/base_docs.html new file mode 100644 index 00000000..5c825bf5 --- /dev/null +++ b/templates/front/base_docs.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} +{% load staticfiles %} + +{% block content %} +
+
+ + + +
+
+ {% block docs_content %} + {% endblock %} +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/front/docs.html b/templates/front/docs.html index 8fa84643..1d145a88 100644 --- a/templates/front/docs.html +++ b/templates/front/docs.html @@ -1,10 +1,9 @@ -{% extends "base.html" %} +{% extends "front/base_docs.html" %} {% load staticfiles %} {% block title %}Documentation - healthchecks.io{% endblock %} -{% block content %} -
+{% block docs_content %}

Summary

@@ -35,6 +34,7 @@ short and simple string "OK".

Here are examples of executing pings from different environments.

+

Crontab

@@ -99,6 +99,7 @@ task runs. Feel free to adjust the curl options to your liking. +

Bash or a shell script

Both curl and wget examples accomplish the same @@ -111,16 +112,20 @@ thing: they fire off a HTTP GET method.

{% include "front/snippets/bash.html" %} +

Python

{% include "front/snippets/python.html" %} +

Node

{% include "front/snippets/node.html" %} +

PHP

{% include "front/snippets/php.html" %} +

Browser

healthchecks.io includes Access-Control-Allow-Origin:* @@ -129,6 +134,7 @@ thing: they fire off a HTTP GET method.

{% include "front/snippets/browser.html" %} +

Email

As an alternative to HTTP/HTTPS requests, @@ -209,5 +215,4 @@ thing: they fire off a HTTP GET method.

-
{% endblock %} \ No newline at end of file diff --git a/templates/front/docs_api.html b/templates/front/docs_api.html new file mode 100644 index 00000000..bf7283cf --- /dev/null +++ b/templates/front/docs_api.html @@ -0,0 +1,113 @@ +{% extends "front/base_docs.html" %} +{% load staticfiles %} + +{% block title %}REST API - healthchecks.io{% endblock %} + +{% block docs_content %} + +

REST API

+

+This is early days for healtchecks.io REST API. For now, there's just +one API call: for creating a new check. +

+ +

Authentication

+

Your requests to healtchecks.io REST API must authenticate using an +API key. By default, an user account on healthchecks.io doesn't have +an API key. You can create one in the Settings page. +

+ +

+The API uses a simple authentication scheme: the API key should be +included in the request body (a JSON document) along other fields. +

+ +

API Requests

+ +

+For POST requests, the healthchecks.io API expects request body to be +a JSON document (not a mulitpart/form-data encoded +form data). +

+ +

API Responses

+ +

+healthchecks.io uses HTTP status codes wherever possible. +In general, 2xx class indicates success, 4xx indicates an client error, +and 5xx indicates a server error. +

+ +

+The response may contain a JSON document with additional data. +

+ +

Create a check

+ +
POST {{ SITE_ROOT }}/api/v1/checks/
+ + + +

+ Creates a new check and returns its ping URL. + All request parameters are optional and will use their default + values if omitted. +

+ +

Request Parameters

+ + + + + + + + + + + + + + + + + + + + + +
name +

string, optional, default value: ""

+

Name for the new check.

+
tags +

string, optional, default value: ""

+

A comma-delimited list of tags for the new check.

+
timeout +

number, optional, default value: {{ default_timeout }}.

+

A number of seconds, the expected period of this check.

+

Minimum: 60 (one minute), maximum: 604800 (one week).

+
grace +

number, optional, default value: {{ default_grace }}.

+

A number of seconds, the grace period for this check.

+

Minimum: 60 (one minute), maximum: 604800 (one week).

+
channels +

string, optional, default value: ""

+

By default, if a check is created through API, no notification + channels are assigned to it. So, when the check goes up or down, + no notifications would be sent. Set this field to a special value "*" + to automatically assign all existing notification channels.

+
+ +

Example Request

+
+curl {{ SITE_ROOT }}/v1/checks/ \
+    -X POST \
+    -d '{"name": "Nightly Backups", "tags": "production,www", "timeout": 3600, "grace": 60}'
+
+ +

Example Response

+
+{"ping_url": "{{ PING_ENDPOINT }}20f2d3d0-efe4-4cc1-a114-a186a225de50"}
+
+ +{% endblock %} \ No newline at end of file