mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Added json_api sample
This commit is contained in:
		
							parent
							
								
									328629b6f4
								
							
						
					
					
						commit
						d0c87f23d1
					
				
					 2 changed files with 18 additions and 1 deletions
				
			
		|  | @ -1,5 +1,13 @@ | ||||||
| require "kemal" | require "kemal" | ||||||
| 
 | 
 | ||||||
|  | # Set root. If not specified the default content_type is 'text' | ||||||
| get "/" do | get "/" do | ||||||
|   "Hello World!" |   "Hello Kemal!" | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | # You can easily access the environment and set content_type like 'application/json'. | ||||||
|  | # Look how easy to build a JSON serving API. | ||||||
|  | get "/user.json" do |env| | ||||||
|  |   env.response.content_type = "application/json" | ||||||
|  |   {name: "Serdar", age: 27}.to_json | ||||||
| end | end | ||||||
|  |  | ||||||
							
								
								
									
										9
									
								
								samples/json_api.cr
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								samples/json_api.cr
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | ||||||
|  | require "kemal" | ||||||
|  | require "json" | ||||||
|  | 
 | ||||||
|  | # You can easily access the environment and set content_type like 'application/json'. | ||||||
|  | # Look how easy to build a JSON serving API. | ||||||
|  | get "/" do |env| | ||||||
|  |   env.response.content_type = "application/json" | ||||||
|  |   {name: "Serdar", age: 27}.to_json | ||||||
|  | end | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue