Skip to content

wrrn/restapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Configuration REST API

Installation

  1. Install postgres
  2. Add user tenable with password insecure
  3. Create database restapi
  4. Install the server (this will install binary in your $GOPATH/bin directory) go get -u github.com/warrenharper/restapi
  5. Run the sql script located in github.com/warrenharper/restapi/env/create_db.sql psql -U tenable -d restapi -a -f env/create_db.sql -h localhost

Running

Assuming $GOPATH/bin is in your path you can just run restapi. This will start the server on port 8080.

Running the tests

The tests assume that you have a database with the name testapi the has an identical schema to that of the database rest api

Vagrant

If you are familiar with vagrant you can cd into the root directory and run vagrant up and all of the enviroment will be setup. You will need to cross compile the binary if you are not running vagrant on a linux machine.

GOOS=linux GOARCH=amd64 go build

#API

Authentication

Log in

POST /login

Input

parameter Description
"username" Required: The username as a string
"password" Required: The password as a string

Example

{
	"name": "john_doe",
	"password": "password"
}

Response

Status Body
200 "Authorized"
401 "Unauthorized"

Log out

POST /logout

Input This requires no input

Response

Status Body
200 "Success"

Note: If you are not authenticated you will receive a status code of 403 when you try to access any thing

Configuration

List configurations

GET /configurations/

NOTE: Note the url ends in a forward slash ("/")

Input This requires no input.

Response

Status
200
{
 "configurations": [
  {
   "id": 1,
   "name": "Config2",
   "hostname": "add.here",
   "port": 3384,
   "username": "warren"
  },
  {
   "id": 2,
   "name": "A",
   "hostname": "b.good",
   "port": 3,
   "username": "abernathy"
  }
 ]
}

Get individual configuration

Get the configuration with the matching name

GET /configurations/:name

Input This requires no input.

Response

Status Body Description
200 See example Found the configuration
404 Could not find the configuration

Example

GET /configurations/Config2
{
 "configurations": [
  {
   "id": 6,
   "name": "Config2",
   "hostname": "add.here",
   "port": 3384,
   "username": "warren"
  },
 ]
}

Add configuration

Add a configuration to the list of configurations

POST /configurations/

Input

parameter Description Type
"name" Required: The name of the configuation string
"hostname" Required: The hostname string
"port" Required: The port int
"username" Required: The username for the configuration string

Example

 {
   "name": "Config2",
   "hostname": "add.here",
   "port": 3384,
   "username": "warren"
}

Response

Status Body Description
200 See example Configuration was added
409 List of configurations that collide with the name of the addee Name collision

Example

{
 "configurations": [
  {
   "id": 6,
   "name": "Config2",
   "hostname": "add.here",
   "port": 3384,
   "username": "warren"
  },
 ]
}

Delete an individual configuration

Delete the configuration with the matching name

DELETE /configurations/:name

Input This requires no input.

Response

Status Body Description
209 Found the configuration
404 Could not find the configuration

Example

DELETE /configurations/Config2

Modify an individaul configuration

PATCH /configurations/:name

Input

parameter Description Type
"name" The name of the configuation string
"hostname" The hostname string
"port" The port int
"username" The username for the configuration string

Note: Any of the input fields that are ommited will remain the same

Response

Status Body Description
200 See example Configuration was added
409 List of configurations that collide with the name of the modified Name collision

Example

PATCH /configurations/Config2
{
 "name": "Config65"
}

Response

{
 "configurations": [
  {
   "id": 6,
   "name": "Config65",
   "hostname": "add.here",
   "port": 3384,
   "username": "warren"
  },
 ]
}

Sorting and Pagination

Sort your configurations and retrieve them by page

Sorting

Add the sort parameter to the GET /configurations/ request with one of the following values:

Value Description
name Sort configurations by name
hostname Sort configurations by hostname
port Sort configurations by port
username Sort configurations by username

Example

GET /configurations/?sort=name

Pagination

To paginate you must have both parameters page and per_page. page is 0 based. per_page cannot be greater than 100.

Example

GET /configurations/?page=0&per_page=50

About

A simple configurations REST API

Resources

Stars

Watchers

Forks

Packages

No packages published