micro-link
is a minimalistic microservice that lets you easily generate and resolve sharable dynamic link (a.k.a deeplink). no database. no fancy architecture. just a microservice powered by micro.
Simply send a POST request to https://micro-link.now.sh
in this way:
POST https://micro-link.now.sh
Request Body:
{
web: "https://google.com" (required),
ios: "google:https://search" (optional),
android: "google:https://search" (optional)
}
please take note that, the "web" link is required because that will always be the fallback link. You can try using tools like Postman or curl
to make the network request:
echo '{"web":"google.com"}' | curl -d @- https://micro-link.now.sh
The response contains a JSON object with the generated dynamic link like this:
{
link: "https://micro-link.now.sh?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWIiOiJodHRwczovL3FhbnZhc3QuY29tIiwiaW9zIjoicWFudmFzdDovL2Rpc2NvdmVyeSIsImlhdCI6MTQ3ODUzMDE3NX0.eQao9zz3sskQTxaOUETQlB-QeYUmHVEqkF8905id-6M"
}
micro-link
simply acts as an API for you to generate dynamic links. How you are going to utilize the generated dynamic link is totally up to your needs.
Simply make a GET request to the generated dynamic link to resolve it:
GET https://micro-link-jzbxhzqoqd.now.sh?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWIiOiJodHRwczovL3FhbnZhc3QuY29tIiwiaW9zIjoicWFudmFzdDovL2Rpc2NvdmVyeSIsImlhdCI6MTQ3ODUzMDE3NX0.eQao9zz3sskQTxaOUETQlB-QeYUmHVEqkF8905id-6M
Depending on the browser that you use to resolve the link, micro-link
will automatically detect the browser's User Agent and redirect to the application or website properly.
Give it a try! Generate a simple dynamic link that resolve to any apps of even your own apps, and open the generated link from your iPhone and Android devices to see it in action.
micro-link
utilizes JSON Web Token to generate a unique dynamic link for the payload (request body) received. That means you have to supply a secret to JWT to generate the unique token. This token is then included in the response object that contains the "generated" dynamic link.
This allows micro-link
to retrieve this token when resolving the dynamic link, and retrieve the payload back for redirection. The redirection is achieved through the use of useragent library that detect the client's user agent and pick the correct redirection link from the payload.
You can easily deploy micro-link
as your own dynamic link microservice as well using Now by Zeit.co. Follow this steps:
$ git clone https://github.com/xkawi/micro-link.git
$ cd micro-link
- modify the
jwtSecret
and optionallytokenQueryKey
found atlib/core.js
$ npm install -g now
(ensure that you are using node v6 and above)$ now
(you may need to login if it is your first time)- open the copied link in the browser and there you have it! your own dynamic link microservice deployed in less than a minute!
Or just click the icon below to deploy your own microservice to Now:
If you look at lib/core.js
, there are a few environment variables that you can utilize, they are namely:
JWT_SECRET
- to store your JWT secret securelyHOST_URL
- used when generating the dynamic link. It is important that thisHOST_URL
can resolve properly, otherwise the dynamic link will not work. By default it uses the deployed url from Now, NOW_URL, which is automatically provided.TOKEN_QUERY_KEY
- if you want to customize the query key such as<HOST_URL>?customKey=<JWT_token>
, you can use this env var to overwrite the default<HOST_URL>?token=<JWT_token>
key
Refer to Now's documentation in handling secrets and environment variables.
- show a landing page if the dynamic link cannot be resolved properly on mobile
- handle Android deeplink the "correct" way (as I am not familiar with this)
- shorten the token? open to any discussion if you have some ideas.
If you would like to contribute to any of the roadmap above or simply want to contribute discussions or anything, go to micro-link
github repo here and fork it, open issues, and of course, don't forget to star it!
Have fun!