Code Monkey home page Code Monkey logo

pastetext-api's Introduction

# PasteText API

This is a simple Python API, built with Flask, that functions like Pastebin. It allows users to upload any text, which is then stored and can be accessed later via a unique link.

## Installation

Install the required Python packages:

```bash
pip install flask flask_sqlalchemy requests

Running the API

Start the Flask development server:

python app.py

A SQLite database will be created in the system's memory to store posted text.

Usage

Posting Text

Use the following Python script with the requests library to interact with the API:

import requests
import json

# URL of the API
url = 'https://paste-gsr8.onrender.com/'

# Your text to send
my_text = '''This is my text. It can be as long as needed, 
and can span multiple lines like this.
'''

# Data to be sent
data = {'content': my_text}

# Headers
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

# POST request
response = requests.post(url, data=json.dumps(data), headers=headers)

# If the POST request is successful, you will receive a response
if response.status_code == 200:
    print('Successfully uploaded.')
    print('Response:', response.json())
else:
    print('Failed to upload.')

Retrieving Text

To retrieve the posted text, make a GET request:

text_id = 'xyz'  # use the actual id you got from the POST response
get_url = url + 'text/' + text_id

response = requests.get(get_url)

if response.status_code == 200:
    print('Successfully retrieved.')
    print('Response:', response.text)
else:
    print('Failed to retrieve.')

Replace the text_id in the sample code with the ID received from the POST request. You can also view the uploaded text in your web browser using the same URL.

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.