Messages

The Messages resource is used to create and list chat messages.

Listing chat messages

A GET request will list all of the service’s chat messages.

Response structure
Path Type Description

_embedded.chatty:messages

Array

An array of Message resources

_links

Object

Links to other resources

page

Object

The pagination information

Example request
$ curl 'http://localhost:8080/api/messages' -i -X GET
Example response
HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
Content-Length: 1452

{
  "_embedded" : {
    "chatty:messages" : [ {
      "text" : "Hello!",
      "timeStamp" : "2021-05-10T09:35:51.039649Z",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/api/messages/7"
        },
        "chatty:chatMessage" : {
          "href" : "http://localhost:8080/api/messages/7{?projection}",
          "templated" : true
        },
        "author" : {
          "href" : "http://localhost:8080/api/messages/7/author{?projection}",
          "templated" : true
        }
      }
    }, {
      "text" : "How are you today?",
      "timeStamp" : "2021-05-10T09:35:51.046624Z",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/api/messages/8"
        },
        "chatty:chatMessage" : {
          "href" : "http://localhost:8080/api/messages/8{?projection}",
          "templated" : true
        },
        "author" : {
          "href" : "http://localhost:8080/api/messages/8/author{?projection}",
          "templated" : true
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/api/messages"
    },
    "profile" : {
      "href" : "http://localhost:8080/api/profile/messages"
    },
    "curies" : [ {
      "href" : "http://localhost:8080/../docs/html5/{rel}.html",
      "name" : "chatty",
      "templated" : true
    } ]
  },
  "page" : {
    "size" : 20,
    "totalElements" : 2,
    "totalPages" : 1,
    "number" : 0
  }
}
Relation Description

self

The Messages resource

profile

The profile describes the data structure of this resource

curies

Curies are used for online documentation

Creating a chat message

A POST request is used to create a chat message

Request structure
Path Type Description

text

String

The text of the chat message

author

String

The author of the chat message. This must be the URL to an existing user resource

Important
Whenever you want to link REST resources, you have to provide the URL to the REST resource you want to link to. In the example below, a chat message needs an author, which is provided by the URL of the corresponding user resource.
Example request
$ curl 'http://localhost:8080/api/messages' -i -X POST \
    -H 'Content-Type: application/hal+json' \
    -d '{
  "author" : "http://localhost:8080/api/users/toedter_k",
  "text" : "Hello!"
}'
Example response
HTTP/1.1 201 Created
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Location: http://localhost:8080/api/messages/6

Chat Message

The chat message resource is used to get and change a single message.

Getting a chat message

Response structure
Path Type Description

text

String

The text of the chat message

timeStamp

String

The timestamp of the chat message

_links

Object

Links to other resources

Example request
$ curl 'http://localhost:8080/api/messages/5' -i -X GET
Example response
HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
Content-Length: 561

{
  "text" : "Hello!",
  "timeStamp" : "2021-05-10T09:35:50.586199Z",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/api/messages/5"
    },
    "chatty:chatMessage" : {
      "href" : "http://localhost:8080/api/messages/5{?projection}",
      "templated" : true
    },
    "author" : {
      "href" : "http://localhost:8080/api/messages/5/author{?projection}",
      "templated" : true
    },
    "curies" : [ {
      "href" : "http://localhost:8080/../docs/html5/{rel}.html",
      "name" : "chatty",
      "templated" : true
    } ]
  }
}
Relation Description

self

the self link to this user

chatty:chatMessage

the (possibly templated) link to this message

author

the author of this message

curies

Curies are used for online documentation