# Vapor fetching single values from the query string using subscripts

**URL:** <https://forums.swift.org/t/vapor-fetching-single-values-from-the-query-string-using-subscripts/86015>\
**Category:** Vapor\
**Created:** [April 14, 2026, 3:52pm UTC](https://forums.swift.org/t/vapor-fetching-single-values-from-the-query-string-using-subscripts/86015 "2026-04-14T15:52:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon68](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@simon68](https://forums.swift.org/u/simon68)\
**Post date:** [April 14, 2026, 3:52pm UTC](https://forums.swift.org/t/vapor-fetching-single-values-from-the-query-string-using-subscripts/86015/1 "2026-04-14T15:52:09Z")

</div>

Hi guys,

in one of my Vapor routes I am using the following snippet:

```swift
let barcode = try req.content.get(String.self, at: "barcode")
        
if let code = try await Barcode.find(barcode, on: req.db) {
...
        }

```

which works fine, provided there is a key `"barcode"` in the content part of the request (otherwise I get a warning)

In fact I don't remember where I got that syntax from : `req.content.get( ..., at: )` , to get a single value from JSON content of a request.

Looking at `docs.vapor.codes/basics/content` at `Single Value` I would think the right syntax should be:

```swift
let barcode: String? = req.query["barcode"]

```

But that gives always `nil`. Do I miss something? Is the first syntax still admitted? If so where is it described ?

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![ptoffy](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ptoffy/32/44481_2.png) [@ptoffy](https://forums.swift.org/u/ptoffy)\
**Post date:** [April 14, 2026, 4:00pm UTC](https://forums.swift.org/t/vapor-fetching-single-values-from-the-query-string-using-subscripts/86015/2 "2026-04-14T16:00:56Z")

</div>

`req.query` fetches the query parameters which are part of the URL. So you might have something like

```http
GET http://localhost:8080/foo?barcode=bar

```

here `barcode` is the query parameter.  
`req.content` on the other hand decodes data from the request body:

```http
POST /foo HTTP/1.1
content-type: application/json
content-length: 18

{"barcode": "bar"}

```

---

<div class="post-metadata">

**Author:** ![simon68](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@simon68](https://forums.swift.org/u/simon68)\
**Post date:** [April 14, 2026, 4:29pm UTC](https://forums.swift.org/t/vapor-fetching-single-values-from-the-query-string-using-subscripts/86015/3 "2026-04-14T16:29:49Z")

</div>

Ok @ptoffy, thanks ! Indeed, that's what is described in the docs.

Any idea where the other one (`req.content.get(..,at: )`) comes from ?

Are there other methods on `req.content` worth knowing?

---

<div class="post-metadata">

**Author:** ![ptoffy](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ptoffy/32/44481_2.png) [@ptoffy](https://forums.swift.org/u/ptoffy)\
**Post date:** [April 14, 2026, 4:33pm UTC](https://forums.swift.org/t/vapor-fetching-single-values-from-the-query-string-using-subscripts/86015/4 "2026-04-14T16:33:50Z")

</div>

You can have a look at [the `ContentContainer` API docs](https://api.vapor.codes/vapor/documentation/vapor/contentcontainer)
