File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 24
24
- [API and static files](#api-and-static-files)
25
25
- [GORM](#gorm)
26
26
- [CORS](#cors)
27
+ - [JSONP](#jsonp)
27
28
- [Basic Auth](#basic-auth)
28
29
- [Status](#status)
29
30
- [Status Auth](#status-auth)
@@ -680,6 +681,54 @@ func GetAllCountries(w rest.ResponseWriter, r *rest.Request) {
680
681
681
682
```
682
683
684
+ #### JSONP
685
+
686
+ Demonstrate how to use the JSONP middleware.
687
+
688
+ The curl demo:
689
+ ``` sh
690
+ curl -i http://127.0.0.1:8080/message
691
+ curl -i http://127.0.0.1:8080/message? cb=parseResponse
692
+ ```
693
+
694
+
695
+ Go code:
696
+ ``` go
697
+ package main
698
+
699
+ import (
700
+ " github.com/ant0ine/go-json-rest/rest"
701
+ " log"
702
+ " net/http"
703
+ )
704
+
705
+ type Message struct {
706
+ Body string
707
+ }
708
+
709
+ func main () {
710
+ handler := rest.ResourceHandler {
711
+ PreRoutingMiddlewares: []rest.Middleware {
712
+ &rest.JsonpMiddleware {
713
+ CallbackNameKey: " cb" ,
714
+ },
715
+ },
716
+ }
717
+ err := handler.SetRoutes (
718
+ &rest.Route {" GET" , " /message" , func (w rest.ResponseWriter , req *rest.Request ) {
719
+ w.WriteJson (&Message{
720
+ Body: " Hello World!" ,
721
+ })
722
+ }},
723
+ )
724
+ if err != nil {
725
+ log.Fatal (err)
726
+ }
727
+ log.Fatal (http.ListenAndServe (" :8080" , &handler))
728
+ }
729
+
730
+ ```
731
+
683
732
#### Basic Auth
684
733
685
734
Demonstrate how to setup AuthBasicMiddleware as a pre-routing middleware.
You can’t perform that action at this time.
0 commit comments