Skip to content

ruanbekker/ruby-webrick-basic-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruby-webrick-basic-api

Ruby Webrick

Run the Server

Using docker:

docker run -it -p 8080:8080 ruanbekker/ruby-api

Make Requests

List all items:

$ curl -H 'Content-Type: application/json' -XGET http://localhost:8080/api
{
    "items":[]
}

Create Items:

$ curl -H 'Content-Type: application/json' -XPOST http://localhost:8080/api -d '{"name": "spotify", "description": "music streaming service"}'
$ curl -H 'Content-Type: application/json' -XPOST http://localhost:8080/api -d '{"name": "netflix", "description": "tv streaming service"}'

List all items:

$ curl -H 'Content-Type: application/json' -XGET http://localhost:8080/api
{
    "items": [
        {"id":1,"name":"spotify","description":"music streaming service"},
        {"id":2,"name":"netflix","description":"tv streaming service"}
    ]
}

Update Item:

$ curl -H 'Content-Type: application/json' -XPUT http://localhost:8080/api -d '{"id": 2, "name": "netflix", "description": "tv streaming service..."}'

Delete Item:

$ curl -H 'Content-Type: application/json' -XDELETE http://localhost:8080/api -d '{"id": 2}'

Routes

  • GET /api
  • POST /api, body: {'name': 'james', 'description': 'foobar'}
  • UPDATE /api, body: {'id': 1, 'name': 'james', 'description': 'foobar'}
  • DELETE /api, body: {'id': 1}