Created
          November 12, 2017 08:24 
        
      - 
      
- 
        Save svetlyak40wt/cb478fa0d55e8cdf42d4826f76d99344 to your computer and use it in GitHub Desktop. 
    A short example of a HTTP api written in Common Lisp's framework Ningle.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ;; Micro-framework for building API | |
| (ql:quickload :ningle) | |
| ;; Now ningle is installed and we need to install a clack which is analog of WSGI | |
| ;; stack from Python | |
| ;; I've pressed C-c C-c to eval this form | |
| (ql:quickload :clack) | |
| ;; To parse json: | |
| (ql:quickload :jonathan) | |
| (defvar *app* (make-instance 'ningle:<app>)) | |
| (setf (ningle:route *app* "/") | |
| ;; in case, if you need to parse or serialize JSON, | |
| ;; use Jonthan library. | |
| (jonathan:to-json '(:foo 100500))) | |
| (defvar *server* nil | |
| "This variable will store currently running server instance.") | |
| (defun start () | |
| (if *server* | |
| (format t "Server already started") | |
| (setf *server* | |
| (clack:clackup *app*)))) | |
| (defun stop () | |
| (if *server* | |
| (clack:stop *server*) | |
| (format t "Server is not running"))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment