DEV Community

Discussion on: Best Practice / Standard for API calls

 
quii profile image
Chris James • Edited

Yup (or at least it should!)

If you happen to have Go installed I've made an example

package main

import (
    "fmt"
    "net/http"
)

func AmazingAPI(response http.ResponseWriter, request *http.Request)  {
    foos := request.URL.Query()["foo"]
    fmt.Fprintf(response, "you foo'd me good %+v", foos)
}

func main() {
    handler := http.HandlerFunc(AmazingAPI)
    http.ListenAndServe(":8080", handler)
}

Hitting http://localhost:8080/?foo=1&foo=2&foo=3

Results in you foo'd me good [1 2 3]

Thread Thread
 
gypsydave5 profile image
David Wickes

Worth noting there's nothing in the URI spec for query to require this behaviour (it doesn't even require key=value, just that query strings are 'usually of the form key=value').

But it's definitely more conventionally used the way that @quii is describing - see for instance this on SO.

Thread Thread
 
rhymes profile image
rhymes

@quii you're right! Better than using commas

Thread Thread
 
quii profile image
Chris James • Edited

Yes it is a shame, but it is for sure the convention

Best thing to do is write a test for your server and see if the library behind it supports it. If your server supports it, you're all good and you'll hopefully make it easier for your clients

Thread Thread
 
rsummerell profile image
Ross Summerell

As much as I like this, I don't think Core/Linq supports this

Thread Thread
 
rsummerell profile image
Ross Summerell

Let me add more detail to that,

I am getting a list of Resource Parameters

FilterBy
OrderBy
etc

This is only taking in the first OrderBy parameter I send in the URL.