README.md in macaw_framework-0.1.5 vs README.md in macaw_framework-0.2.0

- old
+ new

@@ -1,11 +1,11 @@ # MacawFramework <img src="macaw_logo.png" alt= “” style="width: 30%;height: 30%;margin-left: 35%"> This is a framework for developing web applications. Please have in mind that this is still a work in progress and -it is strongly advised to not use it for production purposes for now. Actualy it supports only HTTP. HTTPS and SSL +it is strongly advised to not use it for production purposes for now. Actually it supports only HTTP. and HTTPS/SSL support will be implemented soon. Anyone who wishes to contribute is welcome. ## Installation Install the gem and add to the application's Gemfile by executing: @@ -17,46 +17,63 @@ $ gem install macaw_framework ## Usage The usage of the framework still very simple. Actually it support 5 HTTP verbs: GET, POST, PUT, PATCH and DELETE. -For now, the framework can't resolve client request body and headers. The support for this will be included soon. The default server port is 8080. To choose a different port, create a file with the name `application.json` in the same directory of the script that will start the application with the following content: ```json { "macaw": { "port": 8080, "bind": "localhost", - "threads": 10 + "threads": 10, + "cache": { + "cache_invalidation": 3600 + } } } ``` +Cache invalidation time should be specified in seconds. In order to enable caching, The application.json file +should exist in the app main directory and it need the `cache_invalidation` config set. + Example of usage: ```ruby require 'macaw_framework' require 'json' m = MacawFramework::Macaw.new -m.get('/hello_world') do |context| +m.get('/hello_world', cache: true) do |context| context[:body] # Returns the request body as string context[:params] # Returns query parameters and path variables as a hash context[:headers] # Returns headers as a hash return JSON.pretty_generate({ hello_message: 'Hello World!' }), 200 end +m.post('/hello_world/:path_variable') do |context| + context[:body] # Returns the request body as string + context[:params] # Returns query parameters and path variables as a hash + context[:headers] # Returns headers as a hash + context[:params][:path_variable] # The defined path variable can be found in :params + return JSON.pretty_generate({ hello_message: 'Hello World!' }), 200 +end + m.start! ``` -The above example will start a server and will create a GET endpoint at localhost/hello_world. +The example above starts a server and creates a GET endpoint at localhost/hello_world. -The verb methods must always return a String or nil (Used as response) and a number corresponding the -HTTP Status Code to be returned to the client. +If prometheus is enabled, a get endpoint will be defined at path `/metrics` to collect prometheus metrics. This path +is configurable via the `application.json` file. + +The verb methods must always return a string or nil (used as the response) and a number corresponding to the HTTP status +code to be returned to the client. If an endpoint doesn't return a value or returns nil for both the string and the +code, a default 200 OK status will be sent as the response. ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/ariasdiniz/macaw_framework. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ariasdiniz/macaw_framework/blob/main/CODE_OF_CONDUCT.md).