Something that always seemed to lack a bit of documentation was the Bind method. I know it works with a Post but it also works with a Get. Both are slightly different in how they pass their information to the server. You don’t see it when you have a form and do a normal submit though.
In a RESTfull application you would use a POST to create a new object and a GET for getting information and not changing anything serverside.

Of course there are many other reasons when you should use POST over GET or vice versa.

W3Schools

For this we need some code. In the following example I’m using GET and POST wrong since the POST doesn’t create anything, but I’m just making a point.

Here is a very simple module.

vb.net
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
30
31
32
33
34
Option Strict Off
Option Explicit Off
 
Imports Nancy
Imports Nancy.ModelBinding
 
Namespace Modules
    Public Class ExhibitsModule
        Inherits NancyModule
 
        Public Sub New()
            [Get]("") = Function(parameters)
                            Return View("index")
                        End Function
            [Get]("/persons") = Function(parameters)
                                    Return MakePerson(Bind(Of Person)())
                                End Function
            [Post]("/persons") = Function(parameters)
                                     Return MakePerson(Bind(Of Person)())
                                 End Function
        End Sub
 
        Public Function MakePerson(person As Person) As String
            Return person.LastName & " " & person.FirstName
        End Function
 
 
        Public Class Person
            Public Property FirstName As String
            Public Property LastName As String
        End Class
 
    End Class
End Namespace
Option Strict Off
Option Explicit Off

Imports Nancy
Imports Nancy.ModelBinding

Namespace Modules
    Public Class ExhibitsModule
        Inherits NancyModule

        Public Sub New()
            [Get]("") = Function(parameters)
                            Return View("index")
                        End Function
            [Get]("/persons") = Function(parameters)
                                    Return MakePerson(Bind(Of Person)())
                                End Function
            [Post]("/persons") = Function(parameters)
                                     Return MakePerson(Bind(Of Person)())
                                 End Function
        End Sub

        Public Function MakePerson(person As Person) As String
            Return person.LastName & " " & person.FirstName
        End Function


        Public Class Person
            Public Property FirstName As String
            Public Property LastName As String
        End Class

    End Class
End Namespace

The module has a way to open the view and a way to get and post data.
The get and post methods are exactly the same.

In simple html (a razor view here) we can call both methods in our form by just changing the method. for the rest they are the same.

HTML
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
@Inherits Nancy.ViewEngines.Razor.NancyRazorViewBase(Of String)
 
@Code
    Layout = Nothing
End Code
 
<!DOCTYPE html>
 
<html>
<head>
    <title></title>
    
 
</head>
<body>
    <div>
        <form action="/persons" method="GET">
            <input type="text" name="FirstName" value="testfirstnameget" />
            <input type="text" name="LastName" value="testlastnameget" />
            <button>Submit</button>
        </form>
        <form action="/persons" method="POST">
            <input type="text" name="FirstName" value="testfirstnamepost" />
            <input type="text" name="LastName" value="testlastnamepost" />
            <button>Submit</button>
        </form>   
    </div>
</body>
</html>
@Inherits Nancy.ViewEngines.Razor.NancyRazorViewBase(Of String)

@Code
    Layout = Nothing
End Code

<!DOCTYPE html>

<html>
<head>
    <title></title>
    

</head>
<body>
    <div>
        <form action="/persons" method="GET">
            <input type="text" name="FirstName" value="testfirstnameget" />
            <input type="text" name="LastName" value="testlastnameget" />
            <button>Submit</button>
        </form>
        <form action="/persons" method="POST">
            <input type="text" name="FirstName" value="testfirstnamepost" />
            <input type="text" name="LastName" value="testlastnamepost" />
            <button>Submit</button>
        </form>   
    </div>
</body>
</html>

These days of course nobody uses the plain old submit anymore since it reloads your page, which apparently is very bad.
So we can change our code to no longer submit but to react to an onclick event of the buttons. Don’t forget to make your buttons of type button so they don’t submit the form anymore.
And see the code below with added javascript.

HTML
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@Inherits Nancy.ViewEngines.Razor.NancyRazorViewBase(Of String)
 
@Code
    Layout = Nothing
End Code
 
<!DOCTYPE html>
 
<html>
<head>
    <title></title>
    
 
</head>
<body>
    <div>
        <form>
            <input id="firstnameget" type="text" name="FirstName" value="testfirstnamegetjs" />
            <input id="lastnameget" type="text" name="LastName" value="testlastnamegetjs" />
            <button type="button" onclick="getjs()">Submit</button>
        </form>
        <form>
            <input id="firstnamepost" type="text" name="FirstName" value="testfirstnamepostjs" />
            <input id="lastnamepost" type="text" name="LastName" value="testlastnamepostjs" />
            <button type="button" onclick="postjs()">Submit</button>
        </form> 
        <div><ul id="result"></ul></div>       
    </div>
    <script src="@Url.Content("~/Content/Scripts/jquery-2.1.4.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        function postjs() {
            var xhr = new XMLHttpRequest();
            var data = { FirstName: $("#firstnamepost").val(), LastName: $("#lastnamepost").val() };
            xhr.open("POST", "/persons", true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            xhr.send(JSON.stringify(data));
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    $("#result").append("<li>" + xhr.responseText + "</li>");
                };
            }
        }
        function getjs() {
            var xhr = new XMLHttpRequest();
            var data = {FirstName: $("#firstnameget").val(),LastName: $("#lastnameget").val()};
            xhr.open("GET", "/persons?" + $.param(data) , true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    $("#result").append("<li>" + xhr.responseText + "</li>");
                };
            }
        }
    </script>
</body>
</html>
@Inherits Nancy.ViewEngines.Razor.NancyRazorViewBase(Of String)

@Code
    Layout = Nothing
End Code

<!DOCTYPE html>

<html>
<head>
    <title></title>
    

</head>
<body>
    <div>
        <form>
            <input id="firstnameget" type="text" name="FirstName" value="testfirstnamegetjs" />
            <input id="lastnameget" type="text" name="LastName" value="testlastnamegetjs" />
            <button type="button" onclick="getjs()">Submit</button>
        </form>
        <form>
            <input id="firstnamepost" type="text" name="FirstName" value="testfirstnamepostjs" />
            <input id="lastnamepost" type="text" name="LastName" value="testlastnamepostjs" />
            <button type="button" onclick="postjs()">Submit</button>
        </form> 
        <div><ul id="result"></ul></div>       
    </div>
    <script src="@Url.Content("~/Content/Scripts/jquery-2.1.4.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        function postjs() {
            var xhr = new XMLHttpRequest();
            var data = { FirstName: $("#firstnamepost").val(), LastName: $("#lastnamepost").val() };
            xhr.open("POST", "/persons", true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            xhr.send(JSON.stringify(data));
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    $("#result").append("<li>" + xhr.responseText + "</li>");
                };
            }
        }
        function getjs() {
            var xhr = new XMLHttpRequest();
            var data = {FirstName: $("#firstnameget").val(),LastName: $("#lastnameget").val()};
            xhr.open("GET", "/persons?" + $.param(data) , true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    $("#result").append("<li>" + xhr.responseText + "</li>");
                };
            }
        }
    </script>
</body>
</html>

I used some jquery magic to make the making of the queryparameters easier.

In the Post you pass the data in the send method of the XMLHttpRequest in the GET method you add the data as queryparameters to the url.