FBRoute.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <Foundation/Foundation.h>
  10. @protocol FBResponsePayload;
  11. @class FBRouteRequest;
  12. @class RouteResponse;
  13. NS_ASSUME_NONNULL_BEGIN
  14. typedef __nonnull id<FBResponsePayload> (^FBRouteSyncHandler)(FBRouteRequest *request);
  15. /**
  16. Class that represents route
  17. */
  18. @interface FBRoute : NSObject
  19. /*! Route's verb (eg. POST, GET, DELETE) */
  20. @property (nonatomic, copy, readonly) NSString *verb;
  21. /*! Route's path */
  22. @property (nonatomic, copy, readonly) NSString *path;
  23. /**
  24. Convenience constructor for GET route with given pathPattern
  25. */
  26. + (instancetype)GET:(NSString *)pathPattern;
  27. /**
  28. Convenience constructor for POST route with given pathPattern
  29. */
  30. + (instancetype)POST:(NSString *)pathPattern;
  31. /**
  32. Convenience constructor for PUT route with given pathPattern
  33. */
  34. + (instancetype)PUT:(NSString *)pathPattern;
  35. /**
  36. Convenience constructor for DELETE route with given pathPattern
  37. */
  38. + (instancetype)DELETE:(NSString *)pathPattern;
  39. /**
  40. Convenience constructor for OPTIONS route with given pathPattern
  41. */
  42. + (instancetype)OPTIONS:(NSString *)pathPattern;
  43. /**
  44. Chain-able constructor that handles response with given FBRouteSyncHandler block
  45. */
  46. - (instancetype)respondWithBlock:(FBRouteSyncHandler)handler;
  47. /**
  48. Chain-able constructor that handles response with given FBRouteSyncHandler block
  49. */
  50. - (instancetype)respondWithTarget:(id)target action:(SEL)selector;
  51. /**
  52. Chain-able constructor for route that does NOT require session
  53. */
  54. - (instancetype)withoutSession;
  55. /**
  56. Dispatches response for request
  57. */
  58. - (void)mountRequest:(FBRouteRequest *)request intoResponse:(RouteResponse *)response;
  59. @end
  60. NS_ASSUME_NONNULL_END