Skip to content

Instantly share code, notes, and snippets.

@tmontney
Created August 9, 2017 03:01
Show Gist options
  • Save tmontney/fa4fa13ed01c7ae94b2553dd63a60fe3 to your computer and use it in GitHub Desktop.
Save tmontney/fa4fa13ed01c7ae94b2553dd63a60fe3 to your computer and use it in GitHub Desktop.
On send, route is still processed; error in BeforeRouting sends exception text
Public Class Form1
Dim svr As Grapevine.Server.RestServer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
svr = New Grapevine.Server.RestServer
With svr
.Port = 80
.Host = "0.0.0.0"
.UseHttps = False
AddHandler svr.Router.BeforeRouting, AddressOf BeforeRouting
.LogToConsole.Start()
End With
End Sub
Private Sub BeforeRouting(ByVal Context As Grapevine.Interfaces.Server.HttpContext)
Dim Serializer As New System.Web.Script.Serialization.JavaScriptSerializer
Dim Value As Object = Serializer.DeserializeObject(Context.Request.Payload)
Try
Integer.Parse(Value("Value"))
Catch ex As Exception
Context.Response.SendResponse(System.Text.ASCIIEncoding.ASCII.GetBytes("401"))
End Try
End Sub
<Grapevine.Server.Attributes.RestResource>
Public Class RestRoutes
<Grapevine.Server.Attributes.RestRoute(HttpMethod:=Grapevine.Shared.HttpMethod.POST, PathInfo:="/TEST")>
Public Function TestRoute(ByVal Context As Grapevine.Interfaces.Server.IHttpContext) As Grapevine.Interfaces.Server.IHttpContext
Context.Response.SendResponse(System.Text.ASCIIEncoding.ASCII.GetBytes("200"))
Return Context
End Function
End Class
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment