I'm sorry -- i've incorrectly wrote definition for endpoint from memory. Here is correct definition of second case from my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
type EndPoint =
    | [<EndPoint "/">] Home
    | [<EndPoint "/api">] Api of data: ApiEndPoint
and ApiEndPoint =
    | [<Method "GET /">] ToKnob
    | [<Method "POST /"; Json "data">] FromKnob of data: KnobData
and KnobData =
    {
        [<Json>] knob: float
    }
    [<Website>]
    let Main =
        Application.MultiPage (fun ctx endpoint ->
            match endpoint with
            | EndPoint.Home -> HomePage ctx
            | EndPoint.Api api ->
                match api with
                | ApiEndPoint.FromKnob jdata -> FromKnob ctx jdata
                | ApiEndPoint.ToKnob -> ToKnob ctx
        )

in that case when i test connection for / endpoint all works right but POST and GET queries are returns 404: Not Found Here is simple python3 test code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json
import urllib
import urllib.request

url = 'http://localhost:63626/api'

data = {
        'knob': 2.5
}

#POST
params = json.dumps(data).encode('utf8')
request = urllib.request.Request(url, data=params, headers={'content-type': 'application/json'})
response = urllib.request.urlopen(request)
print(response.read().decode('utf8'))

#GET
response = urllib.request.urlopen(url)
print(response.read().decode('utf8'))
By on 11/16/2015 10:12 AM ()

It seems the ToKnob case of the EndPoint type should be removed in the second snippet, no?

Regardless of that, I don't seem to be able to reproduce your problem here; your second snippet, with or without the extraneous ToKnob case, is correctly parsed as ApiEndPoint ToKnob and ApiEndPoint (FromKnob "jsondata") when requesting GET /api and POST /api, respectively. I defined type KnobData = string to get it to compile and passed "jsondata" as the request body. What does your KnobData type look like?

By on 11/16/2015 8:27 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper