title: How to send a JSON body in a get request with Alamofire
body: <p>I'm facing a problem since 3 weeks now, I'm using an API pretty particular which need a JSON object as body in a GET request. And I think that it's the main problem </p>
  
  <p>I tried to custom my encoding with ParameterEncoding thanks the Alamofire documentation and all the help provide in Stack Overflow and still no success.</p>
  
  <p>When I make my request with Postman or with curl in my terminal, there is no problem but when I develop in swift with Alamofire, I get an internal error 500 or nothing passed in my response (when I set my parameter in my request function with the keyword encoding : JSONEncoding.default).</p>
  
  <p>Here is the curl exemple : </p>
  
  <p>curl -X GET <a href="https://blih.epitech.eu/user/repositories" rel="nofollow noreferrer">https://blih.epitech.eu/user/repositories</a>
  -H 'Content-Type: application/json'
  -d '{"user": account, "signature": password}'</p>
  
  <p>Here is the sample of my code :</p>
  
  <pre><code>/// swift 5
  let userString = #"{"user":"\#(account)","signature":"\#(signaturePassword)"}"#
  let urlString = "https://blih.epitech.eu/repositories"
  
  Alamofire.request(urlString, method: .get, parameters: [:], encoding: JSONStringArrayEncoding.init(string: userString), headers: nil)
      .responseJSON { (response) in
          debugPrint(response)
  }
  </code></pre>
  
  <p>The 'JSONStringArrayEncoding' is a structure with my Custom Encoding :</p>
  
  <pre><code>struct JSONStringArrayEncoding: ParameterEncoding {
      private let myString: String
  
      init(string: String) {
          self.myString = string
      }
  
      func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -&gt; URLRequest {
          var urlRequest = try urlRequest.asURLRequest()
  
          let data = Data(myString.utf8)
  
          if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
              urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
          }
  
          urlRequest.httpBody = data
  
          return urlRequest
      }
  }
  </code></pre>
  
  <p>I expect to have a json Array when the request is successsful :</p>
  
  <pre><code>{
  "message": "Listing successful",
      "repositories": {
          "aaaa": {
              "uuid": "e3a6bea1-c581-5fde-a3a8",
              "url": "https://blih.epitech.eu/repository/aaa"
          }
      }
  }
  </code></pre>
  
  <p>But I get an internal error 500.</p>
  
  <p>Thank you in advance for your help.</p>