Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Server-Side Swift

Server-Side Swift

Talk given in French during XebiCon 2016.

Simone Civetta

November 09, 2016
Tweet

More Decks by Simone Civetta

Other Decks in Programming

Transcript

  1. 1

  2. 6

  3. 8

  4. 9

  5. 10

  6. 11

  7. 12

  8. 13

  9. Plan ➀ Les Origines ➁ État de l'art ➂ Pourquoi

    l'utiliser ? ➃ Swift Server dans la vraie vie ➄ Évolutions 15
  10. 17

  11. 18

  12. 20

  13. 21

  14. 22

  15. 23

  16. 24

  17. 37

  18. 38

  19. 39

  20. 40

  21. 41

  22. 44

  23. 45

  24. 46

  25. 49

  26. 50

  27. 51

  28. 52

  29. 53

  30. 57

  31. 58

  32. 59

  33. 62

  34. 63

  35. 64

  36. 65

  37. 67

  38. 68

  39. 72

  40. 73

  41. 74

  42. 75

  43. 76

  44. 77

  45. 84

  46. 85

  47. 86

  48. Package.swift import PackageDescription let package = Package( name: "xebicon", dependencies:

    [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 0), .Package(url: "https://github.com/feinstruktur/CRabbitMQ", majorVersion: 1) ]) 87
  49. Serveur HTTP import Kitura let router = Router() router.post("/vote/station", handler:

    { request, response, next in do { try processVoteRequest(request) } catch { debugPrint(error) response.send(status: .badRequest) } next() }) Kitura.addHTTPServer(onPort: 8080, with: router) Kitura.run() 88
  50. Build $ swift build Linking CHTTPParser Compile Swift Module 'Socket'

    (3 sources) Compile Swift Module 'HeliumLogger' (1 sources) Compile Swift Module 'SwiftyJSON' (2 sources) Compile Swift Module 'SSLService' (1 sources) Compile Swift Module 'KituraNet' (29 sources) Compile Swift Module 'Kitura' (40 sources) Compile Swift Module 'xebicon' (12 sources) Linking ./.build/debug/xebicon 89
  51. Bilbliothèques C func publish(message: String, exchange: String, key: String) throws

    { guard let connection = self.connection else { throw AMQPConnectorError.notConnected } amqp_basic_publish(connection, Constants.defaultChannel, amqp_cstring_bytes(exchange), amqp_cstring_bytes(key), 0, 0, nil, amqp_cstring_bytes(message)) } 90
  52. Tests func testPostVote() { let router = HTTPController().router performServerTest(router) {

    expectation in self.performRequest("post", path: "vote/station", requestModifier: { request in request.write(from: "{" + "\"trainId\": 1," + "\"media\": \"MOBILE\"," + "\"userId\": \"23de45f\"" + "}") }) { response in XCTAssertEqual(response!.statusCode, HTTPStatusCode.OK) expectation.fulfill() } } } 91
  53. 92

  54. 95

  55. 96

  56. 97

  57. 98

  58. Tester c'est linker Undefined symbols for architecture x86_64: "test2.test2.init ()

    -> test2.test2", referenced from: test2Tests.test2Tests.(testExample () -> ()). (implicit closure #1) in test2Tests.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 102
  59. 106

  60. 107

  61. 116