An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 5.3% on proxy.golang.org
Top 5.8% dependent packages on proxy.golang.org
Top 4.7% dependent repos on proxy.golang.org

proxy.golang.org : github.com/coocood/jas

To build a REST API you need to define resources. A resource is a struct with one or more exported pointer methods that accept only one argument of type `*jas.Context` A `*jas.Context` has everything you need to handle the http request, it embeds a anonymous *http.Request field, so you can call *http.Requst methods directly with *jas.Context. The resource name and method name will be converted to snake case in the url path by default.(can be changed in config). HTTP GET POST PUT DELETE should be the prefix of the method name. Methods with no prefix will handle GET request. Other HTTP request with methods like "HEAD", "OPTIONS" will be routed to resource "Get" method. Examples: On your application start, make a new *jas.Router with jas.NewRouter method, pass all your resources to it. Then you can config the router, see Config type for detail. You can get all the handled path printed. they are separated by '\n' Finally, set the router as http handler and Listen. You can make it more RESTful by put an Id path between the resource name and method name. The id value can be obtained from *jas.Context, resource name with `Id` suffix do the trick. If resource implements ResourceWithGap interface, the handled path will has gap segments between resource name and method name. If method has a suffix "Id", the handled path will append an `:id` segment after the method segment. You can obtain the Id value from *jas.Context, but it only works with none Id resource, because there is only one Id field in *jas.Context. Find methods will return error if the parameter value is invalid. Require methods will stop the execution in the method and respond an error message if the parameter value is invalid. Get json body parameter: Assume we have a request with json body Then we can get the value with Find or Require methods. Find and Require methods accept varargs, the type can be either string or int. string argument to get value from json object, int argumnet to get value form json array. If you want unmarshal json body to struct, the `DisableAutoUnmarshal` option must be set to true. Then you can call `Unmarshal` method to unmarshal json body: HTTP streaming : FlushData will write []byte data without any modification, other data types will be marshaled to json format.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/coocood/jas
License: MIT
Latest release: about 10 years ago
First release: about 10 years ago
Namespace: github.com/coocood
Dependent packages: 1
Dependent repositories: 1
Last synced: 23 days ago

    Loading...
    Readme
    Loading...