Skip to content

REST_LoadData

Julio Carneiro edited this page Nov 21, 2017 · 12 revisions

The REST_LoadData HTTP Request is used to retrieve one single record from a 4D Database. It takes a Table Name and Record Number to retrieve the record data to be sent back.

The POST request payload must include the following arguments/attributes:

  • TableName: name of the table to get the record from
  • RecordNum: the 4D database number of the record to be retrieved
  • CallBackMethod: (optional) a 4D expression to be executed after the record has been retrieved, and before assembling the response
  • VariablesList: a JSON Array describing fields and data from the selected record to return (Base64 encoded)

The TableName must be a valid table in the host database structure, and the Record Number must exist in the database, otherwise an empty object will be returned.

If set, the CallBackMethod will be executed after the record has been retrieved. That allows for additional information to be made available when populating the response (e.g. to retrieve other records).

Before processing the VariablesList, all related one records are made available, so one can include related fields in that list. Only relations that are defined in the Database Structure are handled automatically. For manual relations continue reading.

The VariablesList array lists the fields, or calculated values, to be sent back in the response. Each entry in the array is a JSON object with the following possible attributes:

  • name: the attribute name to use in the response JSON object (usually the field name); the name attribute is mandatory;
  • field: the name of the field whose contents to send back; it can be in the long dot notation format as "Table.Field", which allows one to retrieve data from related records (see below)
  • formula: instead of a field, it is possible to return a calculated value; this attribute can be any valid 4D Expression that returns a string value; when executed, the current record from the selected set is in memory, as well as any related one records
  • joinFK & joinPK: those attributes indicate a field in the 'main' table (joinFK) and one in a related table (joinPK); those values must be in the long dot notation format, and are used to retrieve a related record (examples below); that is useful for manual relations, that is, not defined in the database structure.
  • subTable: indicates that the Field is in fact a list of related records from the Table whose name is indicated in the subTable attribute; joinFK & joinPK attributes are used to retrieve the related records to return.
  • subFields: required if subtable is present, it consists of an Array listing the Fields to be retrieved from the related table; its content follows the same rules as the Columns attribute on REST_GetRecords.

The REST_LoadData response is a JSON object whose attributes correspond to each of the Fields/Values listed in the VariablesList. Each attribute in the response object are named according to the name attribute in the corresponding VariablesList entry.


Sample request:

https://gyazo.com/f13e309d0bc95140c1d5cd3e5053e33d

The VariablesList in the request above, which is sent Base64 encoded, correspond to the following JSON string:

[{"name":"RecordID","field":"Location.RecordID"},
{"name":"CreationDate","field":"Location.CreationDate"},
{"name":"LastUpdateDate","field":"Location.LastUpdateDate"},
{"name":"TimeStamp","field":"Location.TimeStamp"},
{"name":"LocationName","field":"Location.LocationName"},
{"name":"City","field":"Location.City"},
{"name":"Country","field":"Location.Country"},
{"name":"GeoLocation","field":"Location.GeoLocation"},
{"name":"Locale","field":"Location.Locale"}]

And the response to the request above would look something like:

https://gyazo.com/f4cc76bd8c6d1ea5c11d315671131aeb

More Examples

A) Example With Sub-tables

https://gyazo.com/4027e65f18050667e12bc1399c084950

The VariablesList in the request above, which is sent Base64 encoded, correspond to the following JSON string:

[{"name":"ProdCompany","field":"Companies.ShortName"},
{"name":"SeriesName","field":"Series.IMDBTitle"},
{"name":"SeasonName","field":"Seasons.IMDBTitle"},
{"name":"contentProfileList","subTable":"ContentProfile","joinFK":"ContentProfile.FeatureID","joinPK":"Features.FeatureId",
    "subFields":[{"name":"GeneName","field":"GenomeMap.GeneName"},
                 {"name":"GeneVector","field":"GenomeMap.Vector"},
                 {"name":"GeneCluster","field":"GenomeMap.Cluster"},
                 {"name":"CuratorName","field":"_ShellUsers.UserName"},
                 {"name":"RecordID","field":"ContentProfile.RecordID"},
                 {"name":"CreationDate","field":"ContentProfile.CreationDate"},
                 {"name":"LastUpdateDate","field":"ContentProfile.LastUpdateDate"},
                 {"name":"TimeStamp","field":"ContentProfile.TimeStamp"},
                 {"name":"FeatureID","field":"ContentProfile.FeatureID"},
                 {"name":"SeasonID","field":"ContentProfile.SeasonID"},
                 {"name":"SeriesID","field":"ContentProfile.SeriesID"},
                 {"name":"GeneID","field":"ContentProfile.GeneID"},
                 {"name":"CuratorID","field":"ContentProfile.CuratorID"},
                 {"name":"CoordinateValue","field":"ContentProfile.CoordinateValue"}]},
{"name":"FeatureId","field":"Features.FeatureId"},
{"name":"SeriesID","field":"Features.SeriesID"},
{"name":"IMDBID","field":"Features.IMDBID"},
{"name":"IMDBTitle","field":"Features.IMDBTitle"},
{"name":"ProdYear","field":"Features.ProdYear"},
{"name":"ProductionTitle","field":"Features.ProductionTitle"},
{"name":"EpisodeNumber","field":"Features.EpisodeNumber"},
{"name":"ProdCompanyID","field":"Features.ProdCompanyID"},
{"name":"ThemeVector","field":"Features.ThemeVector"},
{"name":"NarrativeVector","field":"Features.NarrativeVector"},
{"name":"ContentVector","field":"Features.ContentVector"},
{"name":"ExecutionVector","field":"Features.ExecutionVector"},
{"name":"StyleVector","field":"Features.StyleVector"},
{"name":"CreationDate","field":"Features.CreationDate"},
{"name":"LastUpdateDate","field":"Features.LastUpdateDate"},
{"name":"TimeStamp","field":"Features.TimeStamp"},
{"name":"SeasonID","field":"Features.SeasonID"},
{"name":"DirectorsList","field":"Features.DirectorsList"},
{"name":"FeatureCast","field":"Features.FeatureCast"},
{"name":"isStarCentered","field":"Features.isStarCentered"},
{"name":"CensorshipRating","field":"Features.CensorshipRating"},
{"name":"CountryOfOrigin","field":"Features.CountryOfOrigin"},
{"name":"OrigLanguages","field":"Features.OrigLanguages"},
{"name":"PosterURL","field":"Features.PosterURL"},
{"name":"NarrativeType","field":"Features.NarrativeType"},
{"name":"ActingType","field":"Features.ActingType"},
{"name":"StarName","field":"Features.StarName"},
{"name":"isControlFeature","field":"Features.isControlFeature"},
{"name":"JustWatchID","field":"Features.JustWatchID"},
{"name":"TMDBID","field":"Features.TMDBID"}]

Please note that some fields come from related tables (first 3 fields), and the request includes a SubTable, with data coming from a related many table, ContentProfile. And joinFK and joinPK properties indicate the fields used to retrieve ContentProfile records that relate to each Features record.


The response to the request above would look something like:

https://gyazo.com/6d203bd45f4dff7b4252efd58df78d7a

Clone this wiki locally