RESTFUL web services consumed by web and native mobile apps with authentication in python using django framework

浪子不回头ぞ 提交于 2019-12-03 00:29:51

You can write RESTful web service with the python standard library, third party libraries are not absolutely necessary.

You should read more about what defines a RESTful service, and start implementing it yourself.

For what it's worth, I use cherrypy as a light framework in a few projects. It's simple and easy to use. The website even has a section about how to implement REST in your application.

I've done it with the api key exchange, like you said and used SSL. Worked fine. There are some caveats to make https requests work right on Android.

private static HttpClient newHttpClient() {
    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(null, null);

    SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", sf, 443));

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
    return new DefaultHttpClient(ccm, params);
}

I've used OAUTH2, which is simpler to implement than OAUTH, but needs SSL to actually make it secure.

Since I've used DJANGO REST Framework, you can find the setup, here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!