Coder Social home page Coder Social logo

awwal234 / scissor-backend Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 19.97 MB

API that helps shorten your link using Python - Flask Restx. Some of the endpoint won't be available to return 201 responses due to free tier e.g QRCODE, CUSTOM LINK, but the code are well written.

Python 98.31% Procfile 0.19% JavaScript 1.49%
flask-restx-api python3

scissor-backend's Introduction

SCISSOR-BACKEND DOCUMENTATION

This project is built as a Capstone Project from AltSchool Africa.
The project is built using flask-restx API. Scissor allows users to shorten URLs by pasting a long URL into the platform and a shorter URL is automatically generated.




Implementation :

  1. URL Shortening
  2. Custom URLs
  3. QR Code Generation
  4. Analytics
  5. Link History



Project Guide


Installation :

# after cloning the repo you can then install all requirements.txt file to run

pip install -r requirements.txt

# the above command will help you install all the packages installed through my env and help you get to work.

- Code review ๐Ÿ‘

#from the first part where we have the url shortening. Below is the code with a simple integration.

@action_namespace.route('/shortenlink')
class ShortenLink(Resource):
    @action_namespace.expect(link_model)
    @limiter.limit('4 per day')
    @jwt_required()
    def post(self):
        '''
            Shorten link
        '''
        data = request.get_json()
        link = data.get('link')
        body = {
            "long_url": link,
            "domain": "bit.ly",
        }
        headers = {
            'Authorization': 'Bearer {}'.format(your_token),
            'Content-type': 'application/json'
        }
        response = requests.post('https://api-ssl.bitly.com/v4/shorten', json=body, headers=headers)
        response_dict = json.loads(response.content.decode('utf-8'))
        if response:
            shorts_link = response_dict['link']
            set_link = LinkModel(link=link, short_link=shorts_link)
            set_link.save()
        
            return response.json(), HTTPStatus.OK
            
#from what you can see, I added a limiter to make a request to that api four(4) per day since i'm running on free tier
# want to check out qrLink?
# Now, this is the thing. This code works but won't provide the base64 image; string you need due to running on free tier, but reading the code and json body you will know this is right ...

@action_namespace.route('/qrlink')
class QRLink(Resource):
    @action_namespace.expect(link_model)
    @jwt_required()
    def post(self):
        '''
            Create QRCode Link using domain and hashed link
        '''
        data = request.get_json()
        link = data.get('link')
        url = 'https://api-ssl.bitly.com/v4/bitlinks/{}/qr'.format(link)
        body = {
              "color": "1133ff",
              "exclude_bitly_logo": True,
              "logo_image_guid": "I123456789",
              "image_format": "png",
              "is_hidden": True
        }
        headers = {
            'Authorization': 'Bearer {}'.format(token),
            'Content-type': 'application/json'
        }
        response = requests.post(url, json=body, headers=headers)
        response_dict = response.content.decode('utf-8').strip('()')
        
        return response_dict, HTTPStatus.CREATED
        

This backend API has a UI to test on.
Lol something like a frontend (yeah.) built with VueJs. Frontend Link. NB: mobile view only

Bitly

scissor-backend's People

Contributors

awwal234 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.