api

package
v0.0.0-...-fcfcbe3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package api implements the REST API for the scrap exchange service.

See also the Scrap Exchange Design Doc http://go/scrap-exchange.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

type Api struct {
	// contains filtered or unexported fields
}

Api supplies the handlers for the scrap exchange REST API.

func New

func New(scrapExchange scrap.ScrapExchange) *Api

New returns a new Api instance.

func (*Api) AddHandlers

func (a *Api) AddHandlers(r chi.Router, option Option)

AddHandlers hooks up the Scrap Exchange REST API to the given router.

The value of 'option' controls if Protected endpoints, such as the one for creating scraps, are added to the router.

+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| URL                                    | Method | Request | Response      | Description                       | Prot |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/scraps/                             | POST   | Scrap   | ScrapID       | Creates a new scrap.              | Y    |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/scraps/{type}/({hash}|{name})       | GET    |         | ScrapBody     | Returns the scrap.                |      |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/scraps/{type}/({hash}|{name})       | DELETE |         |               | Removes the scrap.                | Y    |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/raw/{type}/({hash}|{name})          | GET    |         | text/plain    | Returns the raw scrap.            |      |
|                                        |        |         | image/svg+xml |                                   |      |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/tmpl/{type}/({hash}|{name})/{lang} | GET    |         | text/plain    | Templated scrap.                  |      |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/names/{type}/{name}                 | PUT    | Name    |               | Creates/Updates a named scrap.    | Y    |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/names/{type}/{name}                 | GET    |         | Name          | Retrieves a single named scrap    |      |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/names/{type}/{name}                 | DELETE |         |               | Deletes the scrap name.           | Y    |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+
| /_/_names/{type}/                      | GET    |         | []string      | Returns all named scraps of type. |      |
+----------------------------------------+--------+---------+---------------+-----------------------------------+------+

type Option

type Option int

Option controls which endpoints get added in AddHandlers.

const (
	DoNotAddProtectedEndpoints Option = iota
	AddProtectedEndpoints
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL