Giter Site home page Giter Site logo

apiserv's Introduction

apiserv

An example says more than thousands words (example/api/test.py):

from apiserv.decorators import auth, expose, login, expose_as_model, html
from apiserv.misc import Facebook


@expose
def hello():
	return "hello world"

@expose
def echo(data):
	return data


@expose
def double(num):
	return int(num) * 2



@expose_as_model
class User:


	# access example http://localhost:8080/api/test/models/User
	@staticmethod
	def read_all():
		return [dict(id=0, name="Foo Bar")]

	# access example http://localhost:8080/api/test/models/User/0
	@staticmethod
	def read_one(id):
		assert int(id) == 0
		return User.read_all()[0]

	# PUT
	@staticmethod
	def update(data):
		raise NotImplemented()



@login
@expose
def login(login, nick, pwd):
	if nick == "user" and pwd ==  "pwd":
		login(nick)
		return True
	return False


@auth
@expose
def needs_login(nick):
	return "you are logged in as: " + nick




def handle_access_token(uid, access_token):
	print "got fb access token from {}, its: {}".format(uid, access_token)

facebook = Facebook(
	access_token_cb=handle_access_token,
	redirect_handler_url="http://mydomain.com/api/test/facebookRedirectHandler/",
	facebook_app_id="1234 fb app id",
	facebook_app_secret="my app secret",
	permissions=['publish_actions'])

facebook_login_page = facebook.login
facebook_redirect_handler = facebook.redirect_handler

apiserv's People

Contributors

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