-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): add external API endpoint for creating urls #2069
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
^ ignore the above gitguardian warning, it's from the previously-defined Realised that |
Problem
We want to add an external API endpoint for creating URLs (
POST /api/v1/urls
)See Notion page on external API
Solution
Features:
ApiV1Controller
insrc/server/modules/api/external-v1
, with thecreateUrl
methodshortUrl
(optional),longUrl
UrlV1DTO
type):shortUrl
,longUrl
,state
,clicks
,createdAt
,updatedAt
- note that certain fields e.g.tags
,description
have been restrictedTo map from the original DTOStorableUrl
toUrlV1DTO
, I wrote a private functionsanitizeUrlForApi
in the controller that picks out only the fields that we want to return - is this okay, or is there a better method? Will be expecting this function to be reused in the future for other parts of the API controllerDecided against creating a new mapper, because mappers seem specific to transforming from persistent -> DTOUrlV1Mapper
to map fromStorableUrl
toUrlV1DTO
, which should do for nowUrlManagementService
andUrlRepository
have been changed to additionally take in asource
field, to distinguish between console vs. API created links/api/v1/<...>
routesImprovements:
Short link "<shortUrl>" is used. Click here to find out more
when the short URL is already taken. But it seems weird to return "Click here to find out more" from the backend - the external API definitely shouldn't have that, so I've removed it from the external API but preserved it in the internal API. In the future, we should shift the "Click here" part to the frontendFuture possible improvements:
/api/user/url
to/api/user/urls
, consistent with the external API/api/v1/urls
userId
in request body when creating URL through external APITests
Should write integration tests too, when we have them
Deploy notes
New environment variables:
API_LINK_RANDOM_STR_LENGTH
: length of randomly generatedshortUrl
for API created links, defaults to 8