Which REST operation (GET, PUT, or POST) for validating information?

后端 未结 4 1277
终归单人心
终归单人心 2020-12-29 05:12

My users enter a few information fields in an iOS app. This information must be validated on my server, which has a RESTful API. After validation the UI of the iOS app chang

4条回答
  •  失恋的感觉
    2020-12-29 05:42

    I recommend using a ValidationResource and two requests. Each instance of this resource represents the validation of a set of data. The workflow:

    1. Create new ValidationResource

    • Request: POST /path/to/validations
      • data to validate as the body
    • Response: 201 Created
      • Location: /path/to/validations/

    2. Look up result

    • Request: GET /path/to/validations/
    • Respons: 200 OK
      • body: {'valid': true} or {'valid': false}

    This is a RESTful approach in which the Validation is a Resource with server state.

提交回复
热议问题