add /_info

This commit is contained in:
Alexander Popov 2022-10-07 21:11:20 +03:00
parent efd0097cb5
commit e0699931c3
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C
6 changed files with 32 additions and 4 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
bin/
lib/
config.yml
shard.lock

4
README.md Normal file
View File

@ -0,0 +1,4 @@
This is my API service
## methods
/api/v1.0/smsru_status

View File

@ -7,6 +7,10 @@ version: 0.1.0
# description: |
# Short description of ServicesCheck
targets:
api:
main: src/Services.cr
dependencies:
kemal:
github: kemalcr/kemal

View File

@ -1,6 +1,12 @@
require "yaml"
require "kemal"
require "./modules/*"
CONFIG = File.open("./config.yml") { |file| YAML.parse(file) }
CONFIG.class
APP = {version: "1.0.0"}
get "/" do
render "public/index.html"
end

16
src/modules/_info.cr Normal file
View File

@ -0,0 +1,16 @@
require "json"
get "/info" do |env|
version = APP["version"]
if env.params.query["json"]?
env.response.content_type = "application/json"
data = {version: version}.to_json
data
else
env.response.content_type = "text/plain"
"Vesrion: #{version}"
end
end

View File

@ -1,9 +1,5 @@
require "yaml"
require "http/client"
CONFIG = File.open("./config.yml") { |file| YAML.parse(file) }
CONFIG.class
get "/api/v1.0/smsru_status" do
response = HTTP::Client.get "https://sms.ru/my/free?api_id=#{CONFIG["sms.ru"]["api_id"]}&json=1"
response.body