REST API Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
The Social-Connect project utilizes a centralized networking layer to interact with a RESTful backend service. This system facilitates user social interactions, such as following and unfollowing other accounts, by communicating with a versioned API.
The architecture is built around a singleton UserService that abstracts the underlying network complexity provided by APIClient. Authentication is handled automatically via a secure token storage mechanism, ensuring that all outgoing requests to protected endpoints include the necessary credentials.
API Architecture and Infrastructure
The networking infrastructure is anchored by the APIClient class, which defines the base URL and standard request configurations.
Network Configuration
The system is configured to communicate with the following base environment:
- Base URL:
https://api.socialconnect.com/v1/ - Protocol: HTTPS
- Content-Type:
application/json
Sources: APIClient.swift:4-5
Authentication Mechanism
Requests are authenticated using a Bearer token strategy. The APIClient attempts to retrieve an authToken from the KeychainManager before executing a request. If found, it is added to the Authorization HTTP header.
The diagram above illustrates how the APIClient manages authorization headers during the request lifecycle.
Sources: APIClient.swift:15-18, KeychainManager.swift:10-21
Endpoint Definitions
The following table details the REST endpoints currently implemented via the UserService:
| Method | Endpoint Path | Description | Triggered By |
|---|---|---|---|
| POST | users/{userId}/follow | Initiates a follow action for a specific user. | followUser(userId:completion:) |
| POST | users/{userId}/unfollow | Initiates an unfollow action for a specific user. | unfollowUser(userId:completion:) |
Sources: UserService.swift:8-25
User Management Logic
When an endpoint is successfully called, the system triggers local state updates. Specifically, a NotificationCenter broadcast is sent to notify the application of follow status changes.
This sequence shows the flow from a service call to the eventual local notification upon success.
Sources: UserService.swift:11-14, APIClient.swift:21-34
External Triggers and Deep Linking
API actions can be triggered externally via the DeepLinkHandler. The application handles specific URL schemes to perform automated API requests.
Deep Link to API Mapping
The following logic maps incoming deep link hosts to API service calls:
- Host:
follow-> TriggersUserService.followUserusing theuserIdquery parameter. - Host:
profile-> Navigates to the user profile.
Implementation Detail: Follow Deep Link
private func handleFollowDeepLink(_ components: URLComponents) -> Bool {
guard let userId = components.queryItems?.first(where: { $0.name == "userId" })?.value else {
return false
}
// Follow the user
userService.followUser(userId: userId)
return true
}
Sources: DeepLinkHandler.swift:37-45
Conclusion
The REST API integration in Social-Connect is a structured pipeline starting from AppDelegate or internal services, flowing through a centralized UserService, and executed by a secure APIClient. This design ensures that authentication and base configurations are handled consistently across all social interaction endpoints.