-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRequests.fs
More file actions
29 lines (22 loc) · 795 Bytes
/
Copy pathRequests.fs
File metadata and controls
29 lines (22 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Requests
open System.Text
open System.Net
open System
open Newtonsoft.Json
let httpUrl = "http://localhost:8080"
let getString rawForm =
UTF8.toString rawForm
let getResourceFromResponse<'a> (rawForm: byte[]) =
let fromJson json =
JsonConvert.DeserializeObject(json, typeof<'a>) :?> 'a
getString rawForm |> fromJson
let makeRequest (url:string) (method:string) (content:string) =
let client = new WebClient()
let httpUri = Uri(httpUrl+url)
let (postBytes: byte[]) = Encoding.ASCII.GetBytes(content)
client.Headers.[HttpRequestHeader.ContentType] <- "application/json; charset=utf-8"
let response = client.UploadData(httpUri, method, postBytes)
if method = "GET" then
getResourceFromResponse response
else
getString response