proxy.golang.org : github.com/brocaar/go-restful
Package go-restful, a lean package for creating REST-style WebServices without magic. Example WebService: Example main: A WebService has a collection of Route objects that dispatch incoming Http Requests to a function calls. A Route is defined by a HTTP method, an URL path and (optionally) the MIME types it consumes (Content-Type) and produces (Accept). This package has the logic to find the best matching Route and if found, call its Function. The (*Request, *Response) arguments provide functions for reading information from the request and writing information back to the response. A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. You can use filters to perform generic logging, measurement, authentication, redirect, set response headers etc. In the restful package there are three hooks into the request,response flow where filters can be added. Each filter must define a FilterFunction: Use the following statement to pass the request,response pair to the next filter or RouteFunction These are processed before any registered WebService. These are processed before any Route of a WebService. These are processed before calling the function associated with the Route. See the example https://github.com/emicklei/go-restful/blob/master/examples/restful-filters.go with full implementations. Use the Go standard http.ServeFile function to serve file system assets. See the example https://github.com/emicklei/go-restful/blob/master/examples/restful-serve-static.go with full implementations. Unexpected things happen. If a request cannot be processed because of a failure, your service needs to tell the response what happened and why. For this reason HTTP status codes exist and it is important to use the correct code in every exceptional situation. 400: Bad Request If path or query parameters are not valid (content or type) then use http.StatusBadRequest. 404: Not Found Despite a valid URI, the resource requested may not be available 500: Internal Server Error If the application logic could not process the request (or write the response) then use http.StatusInternalServerError. In addition to setting the correct (error) Http status code, you can choose to write a ServiceError message on the response: (c) 2012,2013, http://ernestmicklei.com. MIT License
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/brocaar/go-restful
License: MIT
Latest release: almost 12 years ago
First release: almost 12 years ago
Namespace: github.com/brocaar
Stars: 2 on GitHub
Forks: 1 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 12 days ago