# The `api/db/<dbname>/classes/<struct_no>` Resource

> The `api/db/<dbname>/classes/<struct_no>` resource executes the following operations for HTTP `GET`, `POST` and `DELETE`:

> - `GET`: Shows the schema for the specified `struct_no`
> - `POST`: Writes records to the database
> - `DELETE`: Deletes all records of the specified class

> ### For an overview see page eXtremeDB Web Service Resources

> # GET

> With the REST server started (listening on port 8083), the following http request will display the schema for the specified `class`:

>         GET http://localhost:8083/api/db/xsqldb/classes/0

> The response displays the schema for the specified `class` in the following format:

>         {
>             "schema":

>             {

>                 "struct_no": 0,
>                 "name": "I",
>                 "flags": 9,
>                 "flags_s":
>                 [
>                     "MCO_DICT_SI_CLASS",
>                     "MCO_DICT_SI_LIST"
>                 ],
>                 "class_code": 1,
>                 "fields"
>                 [

>                     {

>                         "field_no": 0,
>                         "name": "i",
>                         "type": 6,
>                         "type_s": "MCO_DD_INT4",
>                         "flags": 64,
>                         "flags_s":
>                         [
>                             "MCO_DICT_FI_NULLABLE"

>                         ]
>                     },

>                     {

>                         "field_no": 1,
>                         "name": "s",
>                         "type": 16,
>                         "type_s": "MCO_DD_STRING",
>                         "flags": 64,
>                         "flags_s":
>                         [
>                             "MCO_DICT_FI_NULLABLE"

>                         ]
>                     },

>                 ],
>                 "indexes"
>                 [

>                     {
>                         "index_no": 0,
>                         "name": "list_index_",
>                         "flags": 21,
>                         "flags_s":
>                         [
>                             "MCO_DICT_II_UNIQUE",
>                             "MCO_DICT_II_LIST",
>                             "MCO_DICT_II_TREE"
>                         ],
>                         "index": 0,
>                         "n_keys_estimate": 0,
>                         "fields":
>                         [
>                         ]
>                     }
>                 ],
>                 "events"
>                 [

>                 ]
>             }

>         }

> # POST

> The `POST` request writes records to the database. All records are written in the context of a single transaction. In case of a failure, the transaction is rolled back and the database is returned to its previous state; and an HTTP error is returned. On success, HTTP status `200` is returned.

> The request body is a JSON object. The records are passed as an array of JSON objects, where keys correspond to the records' field names. For example, a single record with an integer field `i` and a string field `s` could be inserted with the following JSON object:

>         {
>             "records":
>             [
>                 {
>                     "i": 3,
>                     "s": "test"
>                 }
>             ]
>         }

> Field values must be appropriate for the field types in the database. The web service does not attempt to implicitly cast JSON strings to integer fields, or vice versa. Floating-point values are likewise not rounded to integers. The following are the JSON formatting rules for eXtremeDB data types:

> - Scalar integer and floating point values: JSON numerics
> - Date and time values: timestamps as JSON numerics
> - Boolean values: JSON `true` or `false` literals
> - ASCII fixed- and variable-length strings: JSON strings
> - Wide and double-byte (`wchar`, `nchar`) strings: JSON hex-encoded strings (e.g. `"7400650073007400"` for string `"test"` when encoded using the `UTF-16-LE` encoding)
> - Fixed- and variable-length binary: JSON hex-encoded strings (e.g. `"0a0b0c0d"`)
> - Blobs: JSON hex-encoded strings
> - Structures: JSON objects with keys for field names, just like class records
> - Arrays and vectors: JSON arrays: `[1, 2, 3]`
> - Sequences: JSON arrays: `[1, 2, 3]`

> For example, consider the following table:

>         CREATE TABLE T4(pk INTEGER PRIMARY KEY, str STRING, bin BINARY(3),
>             arr ARRAY(INTEGER), seq SEQUENCE(CHAR(4)), b BOOLEAN);

> The following request inserts 2 records (note that omitted fields are stored as nulls):

>         POST http://localhost:8083/api/db/xsqldb/classes/3
>         {
>             "records":
>             [
>                 {
>                     "pk":1, "str": "string1", "bin": "010203", "arr": [1,2,3,4],
>                     "seq": ["AAAA", "BBB", "CC", "D"], "b": false
>                 },
>                 {
>                     "pk":2, "str": "string2", "b": true
>                 }
>             ]
>         }

> # DELETE

> The `DELETE` request deletes all records of the specified class. For example, the following request deletes all objects of the class with `class_code = 3`:

>         DELETE http://localhost:8083/api/db/xsqldb/classes/3

> On success, the following is returned:

>         200 OK