Giter Club home page Giter Club logo

simpleapi's Introduction

SimpleApi

Simplest api ever created with CRUD and token authentication

Documentation

SimpleApi

Features

  • CRUD operations
  • User authentication
  • Tokens
  • Limitation for api requests (default:300 requests per minute)
Features that comming in next version [v.1.0.1]
  • Upload files on server with Flask-Upload extension implemented

Getting Started

SimpleApi is Flask application developed for fast development of simple APIs,this package uses SQLite3 as default database and SQLAlchemy to comunitcate with database.

Prerequisites

For running this package you will need few other packages

pip install Redis
pip install Flask
pip install SQLAlchemy
pip install Flask-HTTPAuth
  • Redis package is for limation on requests
  • Flask package is micro-framework itself
  • SQLAlchemy package is for communication with SQLite3 database
  • Flask-HTTPAuth package is for authentication users and restricting routes with login required

Installing

SimpleApi is easy to setup you just need to clone or download directory and run it as shown bellow

git clone https://github.com/phpwizz/SimpleApi.git
cd /dir/SimpleApi/
python views.py

And that is it ! Now you have your own api on localhost:8080/api/v1/

Running the tests

Generating authentication token

To generate token in SimpleApi you will first need to be logged in , for that you will first need to create account in

http://localhost:8080/user/auth/token

Output:

{

   "token" : "eyJhbGciOiJIUzI1NiI eyJhbGciOiJIUzI1NiIsImV4cCI6MTUzMTMxNzYxMSwiaWF0IjoxNTMxMzE3MDExfQ.eyJpZCI6MX0.N6KGiEivg3aZCWlkUPjNLNfphUmZx5ssXW56KoPakK0"

}


This token has expiration date of 600 minutes by default but that can be extended on more if is needed.

HTTP Request Method GET

Open any REST api client this tutorial will cover use of Advanced REST client

  • Open a client application

  • For methode chose GET

This will show JSON format for all users

For url put :  http://localhost:8080/api/v1/users

Output:

{
  "Users": [
    {
      "id": 1, 
      "name": "Alex", 
      "picture": "https://thumbs.dreamstime.com/b/profile-icon-male-avatar-portrait-casual-person-silhouette-face-flat-design-vector-47075236.jpg", 
      "user_about": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.  ", 
      "username": "alex123"
    }, 
    {
      "id": 2, 
      "name": "Mark", 
      "picture": null, 
      "user_about": null, 
      "username": "marY2"
    }
  ]
}

HTTP Request Method POST

  • Open a client application

  • For methode chose POST

POST method in this package is used for creating new database entries ex.register new user or creating a new post

Creating new user

For url put :  http://localhost:8080/api/v1/user/register/new

Set headers to Content-Type and application/json

Input:

{
  "username": "test12",
  "password": "test2"
}

Output:

{
"Created": "test12"
}

Application will respond with success message!

If you are familier with curl command you can do it this way

 curl -i -X POST -H 'Content-Type: application/json' -d '{"username":"1","password":"1"}' http://localhost:8080/api/v1/user/register/new

HTTP Request Method PUT

Info : For this step you need to have already registered user

  • Open a client application

  • For methode chose PUT

PUT method in this package is used for updatung already existent database entries ex.change user name , change content for post

Updating user username

For url put :  http://localhost:8080/api/v1/user/id/1/edit/username

Set headers to Content-Type and application/json

Input:

{
  "username": "changedusername"
}

Output:

{
"username": "changedusername"
}

Application will respond with new value added for username!

HTTP Request Method DELETE

  • Open a client application

  • For methode chose DELETE

DELETE method in this package is used for removing ex.users or posts

Removing user with specific id

Set headers to Content-Type and application/json

Output:

{
"Deleted": "Success"
}

Application will respond with success message!

Info: Same process can be applied for managing with posts!

Deployment

Tutorial for deploying any flask application on heroku

Built With

  • Flask - The micro-framework used
  • SQLAlchemy - Database communicator
  • Redis - Used to set limitations on requests

Contributing

Everyone is welcome to contribute to this project.

Versioning

  • Version : v1.0

Authors

On this link will be set all future contributors. The best contributers will be added as co-authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

simpleapi's People

Contributors

nedimf avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.