Closed vani-rf closed 5 months ago
Detail Update :
validate
POST
PUT
PATH
Example :
model
type Badges struct { raiden.ModelBase Id int32 `json:"id,omitempty" column:"name:id;type:integer;primaryKey;nullable:false;default:nextval('badges_id_seq')"` Name string `json:"name,omitempty" validate:"required,min=2" column:"name:name;type:varchar;nullable:false"` CreatedAt *time.Time `json:"created_at,omitempty" column:"name:created_at;type:timestamp;nullable;default:CURRENT_TIMESTAMP"` UpdatedAt *time.Time `json:"updated_at,omitempty" column:"name:updated_at;type:timestamp;nullable;default:CURRENT_TIMESTAMP"` // Table information Metadata string `json:"-" schema:"public" tableName:"badges" rlsEnable:"false" rlsForced:"false"` // Access control Acl string `json:"-" read:"" write:""` }
- controller
type BadgesController struct { raiden.ControllerBase Http string path:"/badges" type:"rest" Model models.Badges }
path:"/badges" type:"rest"
- HTTP Call
// Example CURL
curl --location 'http://localhost:8004/rest/v1/badges' \ --header 'apikey: {{ YOUR API KEY }}' \ --header 'Authorization: Bearer {{ Your Token }}' \ --header 'Content-Type: application/json' \ --header 'Prefer: return=minimal' \ --header 'Cookie: frontend_lang=en_US' \ --data '{ "name": "t"}'
// Example Response
{ "code": "Validation Fail", "details": "{\"Name\":[\"name should be at least 2\"]}", "message": "invalid payload for key : Name" }
Detail Update :
validate
tag in model, use go validator for validating payload in rest controller, only applied in HTTP methodPOST
,PUT
, andPATH
validate
tag when regenerate modelExample :
model
type BadgesController struct { raiden.ControllerBase Http string
path:"/badges" type:"rest"
Model models.Badges }// Example CURL
curl --location 'http://localhost:8004/rest/v1/badges' \ --header 'apikey: {{ YOUR API KEY }}' \ --header 'Authorization: Bearer {{ Your Token }}' \ --header 'Content-Type: application/json' \ --header 'Prefer: return=minimal' \ --header 'Cookie: frontend_lang=en_US' \ --data '{ "name": "t"}'
// Example Response
{ "code": "Validation Fail", "details": "{\"Name\":[\"name should be at least 2\"]}", "message": "invalid payload for key : Name" }