Skip to content

Commit

Permalink
Merge pull request #56 from jgarzik/docs
Browse files Browse the repository at this point in the history
docs: move API docs to separate file
  • Loading branch information
jgarzik authored Feb 18, 2024
2 parents f422622 + b2c0c23 commit 2916855
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 69 deletions.
86 changes: 86 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

# Server API

Connect to HTTP endpoint using any web client.

## API: Service identity and status

```
$ curl http://localhost:8080/
```

Returns JSON describing service:
```
{
"databases" : [
{
"name" : "db"
}
],
"version" : "0.1.0",
"name" : "kvapp"
}
```

## API: Service health check

```
$ curl http://localhost:8080/health
```

Returns JSON describing service health:
```
{
"healthy": true,
}
```

## API: GET (lookup value by key)

Meta-request: GET http://$HOSTNAME:$PORT/api/$DB/$KEY

Append the key to the URI path following the final '/'. In the
following example, "age" is the key and "/api/db" is the base URI:
```
curl http://localhost:8080/api/db/age
```

Returns binary data (application/octet-stream) describing value found,
if present:
```
25
```

## API: PUT (store key and value)

Meta-request: PUT http://$HOSTNAME:$PORT/api/$DB/$KEY

Append the key to the URI path, and provide HTTP body as value. In the
following example, "age" is the key, "25" is the value,
and "/api/db" is the base URI:
```
curl --data-binary 25 -X PUT http://localhost:8080/api/db/age
```

Returns JSON indicating success:
```
{"result":true}
```

## API: DELETE (remove record, based on key)

Meta-request: DELETE http://$HOSTNAME:$PORT/api/$DB/$KEY

Append the key to the URI path following the final '/'. In the
following example, "age" is the key associated with the record
being removed, and "/api/db" is the base URI:
```
curl -X DELETE http://localhost:8080/api/db/age
```

Returns JSON describing value found and removed (if in db):
```
{"result":true}
```


70 changes: 1 addition & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,73 +67,5 @@ $ cargo test

## Server API

Connect to HTTP endpoint using any web client.

### API: Service identity and status

```
$ curl http://localhost:8080/
```

Returns JSON describing service:
```
{
"databases" : [
{
"name" : "db"
}
],
"version" : "0.1.0",
"name" : "kvapp"
}
```

### API: GET (lookup value by key)

Meta-request: GET http://$HOSTNAME:$PORT/api/$DB/$KEY

Append the key to the URI path following the final '/'. In the
following example, "age" is the key and "/api/db" is the base URI:
```
curl http://localhost:8080/api/db/age
```

Returns binary data (application/octet-stream) describing value found,
if present:
```
25
```

### API: PUT (store key and value)

Meta-request: PUT http://$HOSTNAME:$PORT/api/$DB/$KEY

Append the key to the URI path, and provide HTTP body as value. In the
following example, "age" is the key, "25" is the value,
and "/api/db" is the base URI:
```
curl --data-binary 25 -X PUT http://localhost:8080/api/db/age
```

Returns JSON indicating success:
```
{"result":true}
```

### API: DELETE (remove record, based on key)

Meta-request: DELETE http://$HOSTNAME:$PORT/api/$DB/$KEY

Append the key to the URI path following the final '/'. In the
following example, "age" is the key associated with the record
being removed, and "/api/db" is the base URI:
```
curl -X DELETE http://localhost:8080/api/db/age
```

Returns JSON describing value found and removed (if in db):
```
{"result":true}
```

The microservice API is described in the [kvapp API documentation](API.md).

0 comments on commit 2916855

Please sign in to comment.