- ruby 3.1.2
- rails 7.0.3
- postgresql
- Install dependencies
bundle install
- Configure database (copy sample file and replace values)
cp config/database.sample.yml config/database.yml
- Create and migrate database
rails db:create rails db:migrate
- Get the server running
rails s
bundle exec rspec
- create a master.key file
touch config/master.key
- insert shared_master_key in file
echo <shared_master_key> >> config/master.key
- get the api_token from a rails console
Rails.application.credentials.api_token
All API requests require the use of an API key.
To authenticate an API request, you should provide your API key in the Authorization
header as a bearer token.
e.g. "Bearer asdwvwq-wer-xc4-34534-12312"
List endpoints
#### RequestGET v1/endpoints HTTP/1.1
Accept: application/vnd.api+json
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": [
{
"type": "endpoints",
"id": "12345",
"attributes": [
"verb": "GET",
"path": "/greeting",
"response": {
"code": 200,
"headers": {},
"body": "\"{ \"message\": \"Hello, world\" }\""
}
]
}
]
}
Create endpoint
#### RequestPOST v1/endpoints HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "endpoints",
"attributes": {
"verb": "GET",
"path": "/greeting",
"response": {
"code": 200,
"headers": {},
"body": "\"{ \"message\": \"Hello, world\" }\""
}
}
}
}
HTTP/1.1 201 Created
Location: http://localhost:3000/greeting
Content-Type: application/vnd.api+json
{
"data": {
"type": "endpoints",
"id": "12345",
"attributes": {
"verb": "GET",
"path": "/greeting",
"response": {
"code": 200,
"headers": {},
"body": "\"{ \"message\": \"Hello, world\" }\""
}
}
}
}
Update endpoint
#### RequestPATCH v1/endpoints/12345 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "endpoints",
"id": "12345"
"attributes": {
"verb": "POST",
"path": "/greeting",
"response": {
"code": 201,
"headers": {},
"body": "\"{ \"message\": \"Hello, everyone\" }\""
}
}
}
}
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": {
"type": "endpoints",
"id": "12345",
"attributes": {
"verb": "POST",
"path": "/greeting",
"response": {
"code": 201,
"headers": {},
"body": "\"{ \"message\": \"Hello, everyone\" }\""
}
}
}
}
Delete endpoint
#### RequestDELETE v1/endpoints/12345 HTTP/1.1
Accept: application/vnd.api+json
HTTP/1.1 204 No Content
Error response
In case client makes unexpected response or server encountered an internal problem, the api will provide an error response.DELETE v1/endpoints/1234567890 HTTP/1.1
Accept: application/vnd.api+json
HTTP/1.1 404 Not found
Content-Type: application/vnd.api+json
{
"errors": [
{
"code": "not_found",
"detail": "Requested Endpoint with ID `1234567890` does not exist"
}
]
}
Sample scenario
> GET /hello HTTP/1.1
> Accept: application/vnd.api+json
HTTP/1.1 404 Not found
Content-Type: application/vnd.api+json
{
"errors": [
{
"code": "not_found",
"detail": "Requested page `/hello` does not exist"
}
]
}
POST /endpoints HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "endpoints",
"attributes": {
"verb": "GET",
"path": "/hello",
"response": {
"code": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "\"{ \"message\": \"Hello, world\" }\""
}
}
}
}
HTTP/1.1 201 Created
Location: http://localhost:3000/hello
Content-Type: application/vnd.api+json
{
"data": {
"type": "endpoints",
"id": "12345",
"attributes": {
"verb": "GET",
"path": "/hello",
"response": {
"code": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "\"{ \"message\": \"Hello, world\" }\""
}
}
}
}
GET /hello HTTP/1.1
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{ "message": "Hello, world" }
The server responds with HTTP 404 because only GET /hello
endpoint is defined.
> POST /hello HTTP/1.1
> Accept: application/vnd.api+json
HTTP/1.1 404 Not found
Content-Type: application/vnd.api+json
{
"errors": [
{
"code": "not_found",
"detail": "Requested page `/hello` does not exist"
}
]
}