# RESTHost Guide - Working with inputs

**URL:** https://community.linx.software/community/t/resthost-guide-working-with-inputs/460
**Category:** Guide
**Created:** [October 14, 2020, 10:14am UTC](https://community.linx.software/community/t/resthost-guide-working-with-inputs/460 "2020-10-14T10:14:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ronan](https://community.linx.software/community/user_avatar/community.linx.software/ronan/32/433_2.png) [@ronan](https://community.linx.software/community/u/ronan)
#### Post date: [October 14, 2020, 10:14am UTC](https://community.linx.software/community/t/resthost-guide-working-with-inputs/460/1 "2020-10-14T10:14:43Z")

</div>

# Handling Inputs

When a request is received by Linx, input data is passed in to the operation via:

- [Input Parameters](#input-parameters)
  - [Path](#path)
  - [Query](#query)
  - [Headers and Cookies](#header-and-cookies)

- [Request Body](#request-body)
  - [Simple](#simplebody)
  - [Object](#objectbody)
  - [File](#filebody)

These inputs are deserialized into the appropriate TYP to use when building custom logic.

Like any other TYP, the inputs from a request are accessible for selection in the **Properties** of FNC, SVC or EVT in the operation or **event**.

The following sections describe how to handle each type of request input and the typical usage of each.

* * *

## Input Parameters

[Input parameters](https://swagger.io/docs/specification/describing-parameters/) are divided into the following types based on the parameter location:

- [Path](#path)
- [Query](#query)
- [Header and Cookie](#header-and-cookies)

### Path

[Path parameters](https://swagger.io/docs/specification/describing-parameters/#path-parameters) are variable parts of the request URL.

```yaml
 /users/{id}

```

These are typically used to point to a specific resource such as a user’s `id` in the example above.

There can also be multiple path parameters such as:

```yaml
 /users/{id}/task/{taskID}

```

When the `API Definition` specifies that there are path parameters, these will be deserialized into the appropriate TYP to use in the drop-down selectors in the **Designer**.

For example, the below method take's in an `id` value passed in with the `request URL`.

```yaml
paths:
  /resource/{id}:
    get:
      summary: Retrieve the details of specific resource.
      description: Retrieve the details of specific resource.
      operationId: GetSpecificResource
      parameters:
        - name: id
          in: path
          description: id
          required: true
          schema:
            type: string

```

When a request is made, the URL will look like the below:

```http
https://linxdemo.net:8080/resource/27TAHSS737DCHJ

```

This `id` parameter is then accessible from the `$.Parameters.id` of the operation.

* * *

**Linx Designer View:**

In the below example, the path parameter `id` is used to query a specific resource from the database using an [ExecuteSQL FNC](https://linx.software/docs/reference/plugins/database/content/executesql/):

 ![Capture](https://community.linx.software/community/uploads/default/original/2X/a/a22c9b7b9e111395699d1f9ff723819f907f65b6.png)

* * *

### Query

[Query parameters](https://swagger.io/docs/specification/describing-parameters/#query-parameters) are the most common of parameter types. These are passed in as part of the `query string` which appears at the end of the `request URL`.

```http
/users?role=admin&user=Mark

```

When the `API definition` specifies that there are query parameters, these will be deserialized into the appropriate TYP and will be accessible within the operation to build custom logic with.

For example, the below operation take's in a `email` and `name` parameter values passed in the `query string` of the `request URL`.

```yaml
  /users:
    get:
      summary: List users
      description: List users
      operationId: QueryUsers
      parameters:
        - name: name
          in: query
          description: User full name
          schema:
            type: string
        - name: email
          in: query
          description: User email address
          schema:
            type: string

```

The `name` and `email` parameters are then accessible from the `$.Parameters` of the operation which can be used to do custom processing.

* * *

**Linx Designer View:**

In the below example, the query parameter `name` is used to query matching resources from the database using an [ExecuteSQL FNC](https://linx.software/docs/reference/plugins/database/content/executesql/):

 ![Capture2](https://community.linx.software/community/uploads/default/original/2X/4/491ca88af9a322cb8e33eafbac609beeb17acacd.png)

* * *

### Header and Cookies

[Header and Cookie parameters](https://swagger.io/docs/specification/describing-parameters/#header-parameters) can also be used, although typically these would rather be used for authentication purposes and any parameters passed in would be with the [Query](#query) or [Path](#path).

If you explicitly state these objects in the `API Definition` then they will be available in the `$.Parameters` of the operation.

 ![Capture3](https://community.linx.software/community/uploads/default/original/2X/a/abfca343ffa1cc1f016f838a4d30902e2ff79d1d.png)

If you would like to access other header values, then you will need to build custom logic to extract the desired values.

> 📗[**Learn more**](https://community.linx.software/t/resthost-guide-securing-your-api/462#basic-auth-extract-headers) about extracting authorization credentials from request headers.

* * *

## Request Body

The `request body` is defined by the `API definition`, this can either be simple types such as [STR](https://linx.software/docs/reference/plugins/linx/content/string/) , [INT](https://linx.software/docs/reference/plugins/linx/content/integer/) , [LST](https://linx.software/docs/reference/plugins/linx/content/list/) or objects which contain nested TYP and other objects.

### Request Body - Simple Type

The `request body` of an operation can contain a single TYP or field such as a [STR TYP](https://linx.software/docs/reference/plugins/linx/content/string/) , typically however, you would use a object to hold more information for the `request body`.

To use a simple TYP as the `request body`, add the `request body` definition to the path in the `API Definition` like below:

```yaml
      requestBody:
        content:
          text/plain:
            schema:
              type: string

```

This value will be available in the operation’s `$.Parameters.body` to use in the operation.

### Request Body - Object

If you have described your `request body` as an object in the `API Definition`, the values will be parsed from the request into a [TypeTYP](https://linx.software/docs/reference/designer/ui/#add-a-custom-type). This [TypeTYP](https://linx.software/docs/reference/designer/ui/#add-a-custom-type) and its values will be accessible in the ``$.Parameters.body` to use in the operation.

In the below example, the `/users` endpoint receives a `user` object consisting of multiple fields as the request body.

```yaml
  /users:
    post:
      operationId: CreateUser
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewUser'
        description: Details of the new user to register
        required: true

...

  schemas:
    NewUser:
      type: object
      properties:
        username:
          type: string
        email:
          type: string
        password:
          type: string
          format: password
        firstname:
          type: string
        lastname:
          type: string
      required:
        - username
          email
          password
          firstname
          lastname

```

These values are then accessible in the operation to build custom logic with.

* * *

**Linx Designer View:**

In the below example, the input `email` field of the `User` submitted as the `request body` is validated using a [RegularExpression FNC](https://linx.software/docs/reference/plugins/text/content/regularexpression/).

 ![image](https://community.linx.software/community/uploads/default/original/2X/c/cef67fb63e7776af22a6e37361bf0626698cbd4b.png)

### Request Body - File Object

In order to recieve files in a binary format, you must described your `request body` as a binary object in the `API Definition`, the values will be parsed from the request into a LST\<BYT\> TYP. This LST\<BYT\> TYPand its values will be accessible in the `$.Parameters.body` to use in the operation.

In the below example, the `/users` endpoint receives a binary content request body containing the contents of a file.

```yaml
    /users:
    put:
      summary: send file
      description: Upload profile picture
      operationId: UploadPhoto
      requestBody:
          content:
            application/octet-stream: # Can be image/png, image/svg, image/gif, etc.
              schema:
                type: string
                format: binary
          required: true

```

In order to write the contents of the file out to a drive, you must use the [BinaryFileWrite FNC](https://linx.software/docs/reference/plugins/file/content/binaryfilewrite/).

> 💡 **Tip:** Take a look at [this example](https://community.linx.software/t/resthost-sample-solution-crud-and-file-operations/467#uploadphoto) as a guide to creating files from requests.

---

<div class="post-metadata">

### Author: ![ronan](https://community.linx.software/community/user_avatar/community.linx.software/ronan/32/433_2.png) [@ronan](https://community.linx.software/community/u/ronan)
#### Post date: [October 28, 2020, 3:27pm UTC](https://community.linx.software/community/t/resthost-guide-working-with-inputs/460/2 "2020-10-28T15:27:12Z")

</div>



---

<div class="post-metadata">

### Author: ![Pieter-Jan\_Gouws](https://community.linx.software/community/user_avatar/community.linx.software/pieter-jan_gouws/32/1414_2.png) [@Pieter-Jan\_Gouws](https://community.linx.software/community/u/Pieter-Jan_Gouws)
#### Post date: [May 11, 2023, 1:25pm UTC](https://community.linx.software/community/t/resthost-guide-working-with-inputs/460/3 "2023-05-11T13:25:31Z")

</div>

When trying to input content: of type “image/png” in the request body I receive the following error: (Linx 6)

Compiling RESTHost…  
Compilation error:  
(57,133): error CS0234: The type or namespace name ‘IFormFile’ does not exist in the namespace ‘Microsoft.AspNetCore.Http’ (are you missing an assembly reference?)  
(217,647): error CS0234: The type or namespace name ‘IFormFile’ does not exist in the namespace ‘Microsoft.AspNetCore.Http’ (are you missing an assembly reference?)  
(741,140): error CS0234: The type or namespace name ‘IFormFile’ does not exist in the namespace ‘Microsoft.AspNetCore.Http’ (are you missing an assembly reference?)

How can I fix this?

```auto
  /misc/images/{url}:
    post:
      summary: Upload image
      operationId: misc_post_image
      tags:
        - Misc
      parameters:
        - in: path
          name: url
          description: URL of the image to upload
          required: true
          schema:
            type: string
        - in: header
          name: X-StadiumUser_UUID
          required: true
          schema:
            type: string
            format: string
      requestBody:
        content:
          image/png:
            schema:
              type: string
              format: binary

```

---

<div class="post-metadata">

### Author: ![Pieter-Jan\_Gouws](https://community.linx.software/community/user_avatar/community.linx.software/pieter-jan_gouws/32/1414_2.png) [@Pieter-Jan\_Gouws](https://community.linx.software/community/u/Pieter-Jan_Gouws)
#### Post date: [May 11, 2023, 2:52pm UTC](https://community.linx.software/community/t/resthost-guide-working-with-inputs/460/4 "2023-05-11T14:52:36Z")

</div>

With the new release of RestHost 2.0 the API works 💯

Definition have been updated as follow:

```auto
  /misc/images/{url}:
    post:
      summary: Upload image
      operationId: misc_post_image
      tags:
        - Misc
      parameters:
        - in: path
          name: url
          description: URL of the image to upload
          required: true
          schema:
            type: string
        - in: header
          name: X-StadiumUser_UUID
          required: true
          schema:
            type: string
            format: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image:
                  type: string
                  format: binary

```

Thanks team Linx 💪
