기본 콘텐츠로 건너뛰기

1월, 2018의 게시물 표시

django REST API practice like a boss

pycharm 안녕. django project 생성. 실행환경은 virtualenv로 3.6.x virtualenv 생성에 약간 시간 소모. setting.py와 urls.py가 반겨줌 djex1 프로젝트를 만들었음 __init__.py settings.py urls.py wsgi.py 요렇게 생김. 자, 게임을 시작해볼까? option+R 누름. 이런 애가 나옴. startapp product 라고 쳐서 product 업무를 만들어보자. 자동완성이 된다. product 아래 admin.py apps.py models.py tests.py views.py 이런 파일들이 생겼다. rails 생각이 난다. 내용물은 텅텅 비어서 실망스럽다. comment라도 있을 줄 알았는데. 여튼 텍스트로 hello world 같은 건 안찍어본다. 바로 rest API http://www.django-rest-framework.org/tutorial/quickstart/ 돌입한다. pip install djangorestframework 뭔가 설치했으니 requirements.txt로 pip freeze하여 깡통인 곳에서 설치할때 pip install -r requirements.txt로 설치할 수 있게 만들자. pip freeze > requirements.txt REST API framework는 설치했고 DB를 만들자. 먼저 migrate을 돌려주자. option+R 상태에서 migrate 엔터 Running migrations:   Applying contenttypes.0001_initial... OK   Applying auth.0001_initial... OK   Applying admin.0001_initial... OK   Applying admin.0002_logentry_remove_auto_add... OK   Applying conten

firebase functions 위에 올라간 apollo server 에 apollo engine 끼얹기

이전 글에서 계속. https://www.apollographql.com/docs/engine/setup-node.html  보고 진행해보자. 미리 가입하고 키도 받아놓자. ENGINE_API_KEY 를 잘 copy 해놓자. app.use '/graphql',   bodyParser.json()   graphqlExpress {     schema     context: {}     tracing: true     cacheControl: true   } 먼저 /graphql 쪽 graphqlExpress 에 두개의 키(tracing, cacheControl)를 추가하자. npm install --save compression apollo-engine 두 패키지를 설치하고 compression = require 'compression' { Engine } = require 'apollo-engine' 압축과 엔진을 추가하고 engine을 하나 만들자. engine = new Engine   engineConfig:     apiKey: 'service:acidsound-6459:wKt62uPKS9dmxmBhFh-cZA'   endpoint: '/api/graphql'   graphqlPort: process.env.PORT or 80 engine.start() 여기서 graphqlPort를 지정하지 않으면  Error: Neither 'graphqlPort' nor process.env.PORT is set. In order for Apollo Engine to act as a proxy for your GraphQL server, it needs to know which port your GraphQL server is listening on (this is the port number that comes bef

firebase /w functions + graphQL backend 만들기

persistence 영역을 graphQL 로 일반화 하고 apollo engine 같은 cache를 사용하고 싶다. firebase의 functions를 통해 firebase를 불러오는 건 사실상 이중 작업인 것 같지만 apollo engine이 매우 맘에 들어 끌어들이고 싶다. 먼저 해볼 것은 functions에 graphql을 집어넣고 정적데이터를 읽어오는 것 먼저 로컬에서 구현해본다. 프로젝트 폴더를 생성하고 firebase init functions 부터 하자. 프로젝트를 선택(혹은 생성하고 ? What language would you like to use to write Cloud Functions? JavaScript ✔  Wrote functions/package.json ✔  Wrote functions/index.js 그냥 firebase init 하고 functions를 선택하는 것과는 달리 뭔가 기본 scaffold를 생성해줘서 좋다. {   "functions": {     "source": "functions"   } } 디폴트로 이렇게 해주자. index.coffee 로 get 테스트. exports하는 놈 이름이 functions 이름이 되고 경로도 /[exports한 놈]/ 이 되는 점이 특징이다. functions = require 'firebase-functions' admin = require 'firebase-admin' admin.initializeApp functions.config().firebase exports.addMessage = functions.https.onRequest (req, res)->   original = req.query.text?   admin.firestore()     .collection 'messages'     .add { original }