Created
          April 10, 2018 23:13 
        
      - 
      
 - 
        
Save siavashalipour/57d113898ade24b0f8434cf96d668944 to your computer and use it in GitHub Desktop.  
    ServerSideSwift - First part of Application.swift
  
        
  
    
      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
    
  
  
    
  | func postInit() throws { | |
| // Endpoints | |
| initializeHealthRoutes(app: self) | |
| let dbServiceCollection = dbService.getCollection() | |
| // register | |
| router.all("/register", middleware: BodyParser()) | |
| router.post("/register") { request, response, next in | |
| guard let parsedBody = request.body else { | |
| next() | |
| return | |
| } | |
| switch parsedBody { | |
| case .json(let jsonBody): | |
| let jsonData = try JSONSerialization.data(withJSONObject: jsonBody, options: .prettyPrinted) | |
| let user = try JSONDecoder().decode(UserModel.self, from: jsonData) | |
| try dbServiceCollection?.append(user.createDocument()) | |
| try response.send(user).end() | |
| default: | |
| break | |
| } | |
| next() | |
| } | |
| // ... | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment