• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

go-restful-2.9.5/H16-May-2019-

log/H06-Oct-2020-

.gitignoreH A D06-Oct-2020906

.travis.ymlH A D06-Oct-202045

CHANGES.mdH A D06-Oct-20207.1 KiB

LICENSEH A D06-Oct-20201 KiB

MakefileH A D06-Oct-202091

README.mdH A D06-Oct-20204.3 KiB

SrcfileH A D06-Oct-202027

bench_test.shH A D06-Oct-2020353

compress.goH A D06-Oct-20203.7 KiB

compressor_cache.goH A D06-Oct-20203.1 KiB

compressor_pools.goH A D06-Oct-20202.3 KiB

compressors.goH A D06-Oct-20201.5 KiB

constants.goH A D06-Oct-20201.5 KiB

container.goH A D06-Oct-202013 KiB

cors_filter.goH A D06-Oct-20205.9 KiB

coverage.shH A D06-Oct-202067

curly.goH A D06-Oct-20205.5 KiB

curly_route.goH A D06-Oct-20201.2 KiB

doc.goH A D06-Oct-20207.3 KiB

entity_accessors.goH A D06-Oct-20205 KiB

filter.goH A D06-Oct-20201.6 KiB

json.goH A D06-Oct-2020172

jsoniter.goH A D06-Oct-2020247

jsr311.goH A D06-Oct-20209.4 KiB

logger.goH A D06-Oct-2020921

mime.goH A D06-Oct-20201.4 KiB

options_filter.goH A D06-Oct-20201.4 KiB

parameter.goH A D06-Oct-20204.1 KiB

path_expression.goH A D06-Oct-20202.5 KiB

path_processor.goH A D06-Oct-20201.8 KiB

request.goH A D06-Oct-20203.9 KiB

response.goH A D06-Oct-202010 KiB

route.goH A D06-Oct-20205.1 KiB

route_builder.goH A D06-Oct-202010.5 KiB

router.goH A D06-Oct-2020766

service_error.goH A D06-Oct-2020708

web_service.goH A D06-Oct-202010 KiB

web_service_container.goH A D06-Oct-20201.2 KiB

README.md

1go-restful
2==========
3package for building REST-style Web Services using Google Go
4
5[![Build Status](https://travis-ci.org/emicklei/go-restful.png)](https://travis-ci.org/emicklei/go-restful)
6[![Go Report Card](https://goreportcard.com/badge/github.com/emicklei/go-restful)](https://goreportcard.com/report/github.com/emicklei/go-restful)
7[![GoDoc](https://godoc.org/github.com/emicklei/go-restful?status.svg)](https://godoc.org/github.com/emicklei/go-restful)
8
9- [Code examples](https://github.com/emicklei/go-restful/tree/master/examples)
10
11REST asks developers to use HTTP methods explicitly and in a way that's consistent with the protocol definition. This basic REST design principle establishes a one-to-one mapping between create, read, update, and delete (CRUD) operations and HTTP methods. According to this mapping:
12
13- GET = Retrieve a representation of a resource
14- POST = Create if you are sending content to the server to create a subordinate of the specified resource collection, using some server-side algorithm.
15- PUT = Create if you are sending the full content of the specified resource (URI).
16- PUT = Update if you are updating the full content of the specified resource.
17- DELETE = Delete if you are requesting the server to delete the resource
18- PATCH = Update partial content of a resource
19- OPTIONS = Get information about the communication options for the request URI
20
21### Example
22
23```Go
24ws := new(restful.WebService)
25ws.
26	Path("/users").
27	Consumes(restful.MIME_XML, restful.MIME_JSON).
28	Produces(restful.MIME_JSON, restful.MIME_XML)
29
30ws.Route(ws.GET("/{user-id}").To(u.findUser).
31	Doc("get a user").
32	Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")).
33	Writes(User{}))
34...
35
36func (u UserResource) findUser(request *restful.Request, response *restful.Response) {
37	id := request.PathParameter("user-id")
38	...
39}
40```
41
42[Full API of a UserResource](https://github.com/emicklei/go-restful/tree/master/examples/restful-user-resource.go)
43
44### Features
45
46- Routes for request → function mapping with path parameter (e.g. {id}) support
47- Configurable router:
48	- (default) Fast routing algorithm that allows static elements, regular expressions and dynamic parameters in the URL path (e.g. /meetings/{id} or /static/{subpath:*}
49	- Routing algorithm after [JSR311](http://jsr311.java.net/nonav/releases/1.1/spec/spec.html) that is implemented using (but does **not** accept) regular expressions
50- Request API for reading structs from JSON/XML and accesing parameters (path,query,header)
51- Response API for writing structs to JSON/XML and setting headers
52- Customizable encoding using EntityReaderWriter registration
53- Filters for intercepting the request → response flow on Service or Route level
54- Request-scoped variables using attributes
55- Containers for WebServices on different HTTP endpoints
56- Content encoding (gzip,deflate) of request and response payloads
57- Automatic responses on OPTIONS (using a filter)
58- Automatic CORS request handling (using a filter)
59- API declaration for Swagger UI ([go-restful-openapi](https://github.com/emicklei/go-restful-openapi), see [go-restful-swagger12](https://github.com/emicklei/go-restful-swagger12))
60- Panic recovery to produce HTTP 500, customizable using RecoverHandler(...)
61- Route errors produce HTTP 404/405/406/415 errors, customizable using ServiceErrorHandler(...)
62- Configurable (trace) logging
63- Customizable gzip/deflate readers and writers using CompressorProvider registration
64
65## How to customize
66There are several hooks to customize the behavior of the go-restful package.
67
68- Router algorithm
69- Panic recovery
70- JSON decoder
71- Trace logging
72- Compression
73- Encoders for other serializers
74- Use [jsoniter](https://github.com/json-iterator/go) by build this package using a tag, e.g. `go build -tags=jsoniter .`
75
76TODO: write examples of these.
77
78## Resources
79
80- [Example posted on blog](http://ernestmicklei.com/2012/11/go-restful-first-working-example/)
81- [Design explained on blog](http://ernestmicklei.com/2012/11/go-restful-api-design/)
82- [sourcegraph](https://sourcegraph.com/github.com/emicklei/go-restful)
83- [showcase: Zazkia - tcp proxy for testing resiliency](https://github.com/emicklei/zazkia)
84- [showcase: Mora - MongoDB REST Api server](https://github.com/emicklei/mora)
85
86Type ```git shortlog -s``` for a full list of contributors.
87
88© 2012 - 2018, http://ernestmicklei.com. MIT License. Contributions are welcome.
89